diff options
author | dan <dan.abramov@gmail.com> | 2024-05-11 20:35:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-11 20:35:08 +0100 |
commit | 08462375ca12576ce588da464e6d418a53d6f55f (patch) | |
tree | c3154091999bd3dc26b7b9496dc3ae813094fe4f /src/state/queries/preferences | |
parent | 51b4b22dec9eb48a10befddd30ebff0bd999dc40 (diff) | |
download | voidsky-08462375ca12576ce588da464e6d418a53d6f55f.tar.zst |
Fix flashes when replacing For You (#3967)
* Fix flashes when replacing For You * Switch to Discover if pinned after removing
Diffstat (limited to 'src/state/queries/preferences')
-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() |