diff options
Diffstat (limited to 'src/state/queries/preferences/index.ts')
-rw-r--r-- | src/state/queries/preferences/index.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index b3d2fa9ec..555fd85a4 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -6,6 +6,7 @@ import { import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' import {track} from '#/lib/analytics/analytics' +import {PROD_DEFAULT_FEED} from '#/lib/constants' import {replaceEqualDeep} from '#/lib/functions' import {getAge} from '#/lib/strings/time' import {STALE} from '#/state/queries' @@ -244,6 +245,45 @@ export function useRemoveFeedMutation() { }) } +export function useReplaceForYouWithDiscoverFeedMutation() { + const queryClient = useQueryClient() + const {getAgent} = useAgent() + + return useMutation({ + mutationFn: async ({ + forYouFeedConfig, + discoverFeedConfig, + }: { + forYouFeedConfig: AppBskyActorDefs.SavedFeed | undefined + discoverFeedConfig: AppBskyActorDefs.SavedFeed | undefined + }) => { + if (forYouFeedConfig) { + await getAgent().removeSavedFeeds([forYouFeedConfig.id]) + } + if (!discoverFeedConfig) { + await getAgent().addSavedFeeds([ + { + type: 'feed', + value: PROD_DEFAULT_FEED('whats-hot'), + pinned: true, + }, + ]) + } else { + await getAgent().updateSavedFeeds([ + { + ...discoverFeedConfig, + pinned: true, + }, + ]) + } + // triggers a refetch + await queryClient.invalidateQueries({ + queryKey: preferencesQueryKey, + }) + }, + }) +} + export function useUpdateSavedFeedsMutation() { const queryClient = useQueryClient() const {getAgent} = useAgent() |