fix: close last conversation should set view state to welcome
This commit is contained in:
parent
d0e484a663
commit
52abf5556b
@ -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("");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user