From 8a5f993f8d8e617fe63103589d9c17c8e370537e Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 5 Mar 2024 18:03:24 +0800 Subject: [PATCH] Allow toggling the fetch content type per feed --- .../mutations/updateSubscriptionMutation.ts | 2 + .../queries/useGetSubscriptionsQuery.tsx | 10 ++++- packages/web/pages/settings/feeds/index.tsx | 43 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/web/lib/networking/mutations/updateSubscriptionMutation.ts b/packages/web/lib/networking/mutations/updateSubscriptionMutation.ts index e308c77d3..09a0d5e52 100644 --- a/packages/web/lib/networking/mutations/updateSubscriptionMutation.ts +++ b/packages/web/lib/networking/mutations/updateSubscriptionMutation.ts @@ -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( diff --git a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx index 764b732d9..b05d64eb9 100644 --- a/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetSubscriptionsQuery.tsx @@ -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 } } diff --git a/packages/web/pages/settings/feeds/index.tsx b/packages/web/pages/settings/feeds/index.tsx index 540735174..2588f096c 100644 --- a/packages/web/pages/settings/feeds/index.tsx +++ b/packages/web/pages/settings/feeds/index.tsx @@ -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 => { + 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 )}`} + } onClick={() => {