mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add a button to pause rss feed
This commit is contained in:
parent
3a0c1c7369
commit
b403dea247
6 changed files with 57 additions and 3 deletions
|
|
@ -3031,6 +3031,7 @@ export type UpdateSubscriptionInput = {
|
|||
id: Scalars['ID'];
|
||||
lastFetchedAt?: InputMaybe<Scalars['Date']>;
|
||||
name?: InputMaybe<Scalars['String']>;
|
||||
status?: InputMaybe<SubscriptionStatus>;
|
||||
};
|
||||
|
||||
export type UpdateSubscriptionResult = UpdateSubscriptionError | UpdateSubscriptionSuccess;
|
||||
|
|
|
|||
|
|
@ -2353,6 +2353,7 @@ input UpdateSubscriptionInput {
|
|||
id: ID!
|
||||
lastFetchedAt: Date
|
||||
name: String
|
||||
status: SubscriptionStatus
|
||||
}
|
||||
|
||||
union UpdateSubscriptionResult = UpdateSubscriptionError | UpdateSubscriptionSuccess
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ export const subscriptionsResolver = authorized<
|
|||
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
|
||||
.where({
|
||||
user: { id: uid },
|
||||
status: SubscriptionStatus.Active,
|
||||
status:
|
||||
subscriptionType == SubscriptionType.Newsletter
|
||||
? SubscriptionStatus.Active
|
||||
: undefined, // only return active subscriptions for newsletter
|
||||
type: subscriptionType || SubscriptionType.Newsletter, // default to newsletter
|
||||
})
|
||||
.orderBy('subscription.' + sortBy, sortOrder)
|
||||
|
|
@ -315,7 +318,6 @@ export const updateSubscriptionResolver = authorized<
|
|||
const subscription = await getRepository(Subscription).findOneBy({
|
||||
id: input.id,
|
||||
user: { id: uid },
|
||||
status: SubscriptionStatus.Active,
|
||||
})
|
||||
if (!subscription) {
|
||||
log.info('subscription not found')
|
||||
|
|
@ -332,6 +334,7 @@ export const updateSubscriptionResolver = authorized<
|
|||
lastFetchedAt: input.lastFetchedAt
|
||||
? new Date(input.lastFetchedAt)
|
||||
: undefined,
|
||||
status: input.status || undefined,
|
||||
})
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -2511,6 +2511,7 @@ const schema = gql`
|
|||
name: String
|
||||
description: String
|
||||
lastFetchedAt: Date
|
||||
status: SubscriptionStatus
|
||||
}
|
||||
|
||||
union UpdateSubscriptionResult =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { gql } from 'graphql-request'
|
||||
import { gqlFetcher } from '../networkHelpers'
|
||||
import { Subscription } from '../queries/useGetSubscriptionsQuery'
|
||||
import {
|
||||
Subscription,
|
||||
SubscriptionStatus,
|
||||
} from '../queries/useGetSubscriptionsQuery'
|
||||
|
||||
interface UpdateSubscriptionResult {
|
||||
updateSubscription: UpdateSubscription
|
||||
|
|
@ -22,6 +25,7 @@ interface UpdateSubscriptionInput {
|
|||
lastFetchedAt?: Date
|
||||
name?: string
|
||||
description?: string
|
||||
status?: SubscriptionStatus
|
||||
}
|
||||
|
||||
export async function updateSubscriptionMutation(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { formattedDateTime } from '../../../lib/dateFormatting'
|
|||
import { unsubscribeMutation } from '../../../lib/networking/mutations/unsubscribeMutation'
|
||||
import { updateSubscriptionMutation } from '../../../lib/networking/mutations/updateSubscriptionMutation'
|
||||
import {
|
||||
SubscriptionStatus,
|
||||
SubscriptionType,
|
||||
useGetSubscriptionsQuery,
|
||||
} from '../../../lib/networking/queries/useGetSubscriptionsQuery'
|
||||
|
|
@ -30,6 +31,8 @@ export default function Rss(): JSX.Element {
|
|||
const [onDeleteId, setOnDeleteId] = useState<string>('')
|
||||
const [onEditId, setOnEditId] = useState('')
|
||||
const [onEditName, setOnEditName] = useState('')
|
||||
const [onPauseId, setOnPauseId] = useState('')
|
||||
const [onEditStatus, setOnEditStatus] = useState<SubscriptionStatus>()
|
||||
|
||||
async function updateSubscription(): Promise<void> {
|
||||
const result = await updateSubscriptionMutation({
|
||||
|
|
@ -61,6 +64,19 @@ export default function Rss(): JSX.Element {
|
|||
revalidate()
|
||||
}
|
||||
|
||||
async function onPause(): Promise<void> {
|
||||
const result = await updateSubscriptionMutation({
|
||||
id: onPauseId,
|
||||
status: onEditStatus,
|
||||
})
|
||||
if (result) {
|
||||
showSuccessToast('RSS feed paused', { position: 'bottom-right' })
|
||||
} else {
|
||||
showErrorToast('Failed to pause', { position: 'bottom-right' })
|
||||
}
|
||||
revalidate()
|
||||
}
|
||||
|
||||
applyStoredTheme(false)
|
||||
|
||||
return (
|
||||
|
|
@ -152,7 +168,18 @@ export default function Rss(): JSX.Element {
|
|||
console.log('onDelete triggered: ', subscription.id)
|
||||
setOnDeleteId(subscription.id)
|
||||
}}
|
||||
onEdit={() => {
|
||||
setOnEditStatus(
|
||||
subscription.status == 'UNSUBSCRIBED'
|
||||
? 'ACTIVE'
|
||||
: 'UNSUBSCRIBED'
|
||||
)
|
||||
setOnPauseId(subscription.id)
|
||||
}}
|
||||
deleteTitle="Delete"
|
||||
editTitle={
|
||||
subscription.status === 'UNSUBSCRIBED' ? 'Unpause' : 'Pause'
|
||||
}
|
||||
sublineElement={
|
||||
<StyledText
|
||||
css={{
|
||||
|
|
@ -188,6 +215,23 @@ export default function Rss(): JSX.Element {
|
|||
onOpenChange={() => setOnDeleteId('')}
|
||||
/>
|
||||
)}
|
||||
|
||||
{onPauseId && (
|
||||
<ConfirmationModal
|
||||
message={
|
||||
'RSS feed will be paused/unpaused. You can revert it at any time.'
|
||||
}
|
||||
onAccept={async () => {
|
||||
setOnPauseId('')
|
||||
setOnEditStatus(undefined)
|
||||
await onPause()
|
||||
}}
|
||||
onOpenChange={() => {
|
||||
setOnPauseId('')
|
||||
setOnEditStatus(undefined)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</SettingsTable>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue