Merge pull request #3634 from omnivore-app/feat/rss-fetch-content-type

Allow toggling the fetch content type per feed
This commit is contained in:
Jackson Harper
2024-03-06 10:40:53 +08:00
committed by GitHub
3 changed files with 53 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
import {
FetchContentType,
Subscription,
SubscriptionStatus,
} from '../queries/useGetSubscriptionsQuery'
@ -28,6 +29,7 @@ export interface UpdateSubscriptionInput {
status?: SubscriptionStatus
autoAddToLibrary?: boolean
isPrivate?: boolean
fetchContentType?: FetchContentType
}
export async function updateSubscriptionMutation(

View File

@ -9,6 +9,12 @@ export enum SubscriptionType {
NEWSLETTER = 'NEWSLETTER',
}
export enum FetchContentType {
ALWAYS = 'ALWAYS',
NEVER = 'NEVER',
WHEN_EMPTY = 'WHEN_EMPTY',
}
export type Subscription = {
id: string
name: string
@ -25,7 +31,7 @@ export type Subscription = {
lastFetchedAt?: string
mostRecentItemDate?: string
fetchContent?: boolean
fetchContentType?: FetchContentType
}
type SubscriptionsQueryResponse = {
@ -66,7 +72,7 @@ export function useGetSubscriptionsQuery(
createdAt
updatedAt
lastFetchedAt
fetchContent
fetchContentType
mostRecentItemDate
}
}

View File

@ -21,6 +21,7 @@ import {
updateSubscriptionMutation,
} from '../../../lib/networking/mutations/updateSubscriptionMutation'
import {
FetchContentType,
SubscriptionStatus,
SubscriptionType,
useGetSubscriptionsQuery,
@ -99,6 +100,23 @@ export default function Rss(): JSX.Element {
revalidate()
}
const updateFetchContent = async (
id: string,
fetchContent: FetchContentType
): Promise<void> => {
const result = await updateSubscriptionMutation({
id,
fetchContentType: fetchContent,
})
if (result) {
showSuccessToast(`Updated feed fetch rule`)
} else {
showErrorToast(`Error updating feed fetch rule`)
}
revalidate()
}
applyStoredTheme()
return (
@ -222,6 +240,31 @@ export default function Rss(): JSX.Element {
subscription.mostRecentItemDate
)}`}
</SpanBox>
<select
tabIndex={-1}
onChange={(event) => {
;(async () => {
updateFetchContent(
subscription.id,
event.target.value as FetchContentType
)
})()
}}
defaultValue={subscription.fetchContentType}
style={{
padding: '5px',
marginTop: '5px',
borderRadius: '6px',
minWidth: '196px',
}}
onClick={(event) => {
event.stopPropagation()
}}
>
<option value="ALWAYS">Fetch link: Always</option>
<option value="NEVER">Fetch link: Never</option>
<option value="WHEN_EMPTY">Fetch link: When empty</option>
</select>
</VStack>
}
onClick={() => {