fix: remove list from pinned once deleted (#2705)

zio/stable
Mary 2024-02-07 03:26:57 +07:00 committed by GitHub
parent 2d13f3b367
commit 41860d8b80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 1 deletions

View File

@ -55,6 +55,7 @@ import {
usePreferencesQuery, usePreferencesQuery,
usePinFeedMutation, usePinFeedMutation,
useUnpinFeedMutation, useUnpinFeedMutation,
useSetSaveFeedsMutation,
} from '#/state/queries/preferences' } from '#/state/queries/preferences'
import {logger} from '#/logger' import {logger} from '#/logger'
import {useAnalytics} from '#/lib/analytics/analytics' import {useAnalytics} from '#/lib/analytics/analytics'
@ -246,9 +247,11 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
useUnpinFeedMutation() useUnpinFeedMutation()
const isPending = isPinPending || isUnpinPending const isPending = isPinPending || isUnpinPending
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const {mutate: setSavedFeeds} = useSetSaveFeedsMutation()
const {track} = useAnalytics() const {track} = useAnalytics()
const isPinned = preferences?.feeds?.pinned?.includes(list.uri) const isPinned = preferences?.feeds?.pinned?.includes(list.uri)
const isSaved = preferences?.feeds?.saved?.includes(list.uri)
const onTogglePinned = React.useCallback(async () => { const onTogglePinned = React.useCallback(async () => {
Haptics.default() Haptics.default()
@ -361,6 +364,16 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
message: _(msg`Are you sure?`), message: _(msg`Are you sure?`),
async onPressConfirm() { async onPressConfirm() {
await listDeleteMutation.mutateAsync({uri: list.uri}) await listDeleteMutation.mutateAsync({uri: list.uri})
if (isSaved || isPinned) {
const {saved, pinned} = preferences!.feeds
setSavedFeeds({
saved: isSaved ? saved.filter(uri => uri !== list.uri) : saved,
pinned: isPinned ? pinned.filter(uri => uri !== list.uri) : pinned,
})
}
Toast.show(_(msg`List deleted`)) Toast.show(_(msg`List deleted`))
track('Lists:Delete') track('Lists:Delete')
if (navigation.canGoBack()) { if (navigation.canGoBack()) {
@ -370,7 +383,18 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
} }
}, },
}) })
}, [openModal, list, listDeleteMutation, navigation, track, _]) }, [
openModal,
list,
listDeleteMutation,
navigation,
track,
_,
preferences,
isPinned,
isSaved,
setSavedFeeds,
])
const onPressReport = useCallback(() => { const onPressReport = useCallback(() => {
openModal({ openModal({