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("");