From 41860d8b8084a6ca7af9f7938008eca86a5d08ab Mon Sep 17 00:00:00 2001
From: Mary <148872143+mary-ext@users.noreply.github.com>
Date: Wed, 7 Feb 2024 03:26:57 +0700
Subject: fix: remove list from pinned once deleted (#2705)

---
 src/view/screens/ProfileList.tsx | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

(limited to 'src/view/screens/ProfileList.tsx')

diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx
index 17c93b037..796464883 100644
--- a/src/view/screens/ProfileList.tsx
+++ b/src/view/screens/ProfileList.tsx
@@ -55,6 +55,7 @@ import {
   usePreferencesQuery,
   usePinFeedMutation,
   useUnpinFeedMutation,
+  useSetSaveFeedsMutation,
 } from '#/state/queries/preferences'
 import {logger} from '#/logger'
 import {useAnalytics} from '#/lib/analytics/analytics'
@@ -246,9 +247,11 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
     useUnpinFeedMutation()
   const isPending = isPinPending || isUnpinPending
   const {data: preferences} = usePreferencesQuery()
+  const {mutate: setSavedFeeds} = useSetSaveFeedsMutation()
   const {track} = useAnalytics()
 
   const isPinned = preferences?.feeds?.pinned?.includes(list.uri)
+  const isSaved = preferences?.feeds?.saved?.includes(list.uri)
 
   const onTogglePinned = React.useCallback(async () => {
     Haptics.default()
@@ -361,6 +364,16 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) {
       message: _(msg`Are you sure?`),
       async onPressConfirm() {
         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`))
         track('Lists:Delete')
         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(() => {
     openModal({
-- 
cgit 1.4.1

