Fix flashes when replacing For You (#3967)
* Fix flashes when replacing For You * Switch to Discover if pinned after removing
This commit is contained in:
parent
51b4b22dec
commit
08462375ca
2 changed files with 54 additions and 34 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue