From cb9f6fb3dbf4baaae263191bdf728a1ecd7ba0cb Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Mon, 27 Mar 2023 23:07:32 +0800 Subject: [PATCH] fix: keep folders expanded --- src/components/Menu/ChatFolder.tsx | 12 +++++++++--- src/components/Menu/NewFolder.tsx | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/Menu/ChatFolder.tsx b/src/components/Menu/ChatFolder.tsx index 43bb16e..ee9245f 100644 --- a/src/components/Menu/ChatFolder.tsx +++ b/src/components/Menu/ChatFolder.tsx @@ -59,9 +59,15 @@ const ChatFolder = ({ }); setChats(updatedChats); - setFoldersName( - useStore.getState().foldersName.filter((name) => name !== folderName) - ); + const updatedFoldersName = [...useStore.getState().foldersName]; + const updatedFoldersExpanded = [...useStore.getState().foldersExpanded]; + + const i = updatedFoldersName.findIndex((name) => name === folderName); + updatedFoldersName.splice(i, 1); + updatedFoldersExpanded.splice(i, 1); + + setFoldersName(updatedFoldersName); + setFoldersExpanded(updatedFoldersExpanded); setIsDelete(false); }; diff --git a/src/components/Menu/NewFolder.tsx b/src/components/Menu/NewFolder.tsx index b811e2c..65ab7d6 100644 --- a/src/components/Menu/NewFolder.tsx +++ b/src/components/Menu/NewFolder.tsx @@ -8,6 +8,7 @@ const NewFolder = () => { const { t } = useTranslation(); const generating = useStore((state) => state.generating); const setFoldersName = useStore((state) => state.setFoldersName); + const setFoldersExpanded = useStore((state) => state.setFoldersExpanded); const addFolder = () => { let folderIndex = 1; @@ -23,6 +24,7 @@ const NewFolder = () => { } setFoldersName([name, ...useStore.getState().foldersName]); + setFoldersExpanded([false, ...useStore.getState().foldersExpanded]); }; return (