From 52abf5556b39ea7d342cad7d1fa5f7cb27592fa4 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 3 Oct 2023 16:20:12 +0700 Subject: [PATCH] fix: close last conversation should set view state to welcome --- web/app/_hooks/useDeleteConversation.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/web/app/_hooks/useDeleteConversation.ts b/web/app/_hooks/useDeleteConversation.ts index df1cbd96c..61a3c3653 100644 --- a/web/app/_hooks/useDeleteConversation.ts +++ b/web/app/_hooks/useDeleteConversation.ts @@ -12,6 +12,10 @@ import { showingProductDetailAtom, showingAdvancedPromptAtom, } from "@/_helpers/atoms/Modal.atom"; +import { + MainViewState, + setMainViewStateAtom, +} from "@/_helpers/atoms/MainView.atom"; export default function useDeleteConversation() { const [userConversations, setUserConversations] = useAtom( @@ -23,14 +27,19 @@ export default function useDeleteConversation() { const activeConvoId = useAtomValue(getActiveConvoIdAtom); const setActiveConvoId = useSetAtom(setActiveConvoIdAtom); const deleteMessages = useSetAtom(deleteConversationMessage); + const setMainViewState = useSetAtom(setMainViewStateAtom); const deleteConvo = async () => { if (activeConvoId) { try { await execute(DataService.DELETE_CONVERSATION, activeConvoId); - setUserConversations( - userConversations.filter((c) => c.id !== activeConvoId) + const currentConversations = userConversations.filter( + (c) => c.id !== activeConvoId ); + setUserConversations(currentConversations); + if (currentConversations.length === 0) { + setMainViewState(MainViewState.Welcome); + } deleteMessages(activeConvoId); setActiveConvoId(undefined); setCurrentPrompt("");