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,
|
showingProductDetailAtom,
|
||||||
showingAdvancedPromptAtom,
|
showingAdvancedPromptAtom,
|
||||||
} from "@/_helpers/atoms/Modal.atom";
|
} from "@/_helpers/atoms/Modal.atom";
|
||||||
|
import {
|
||||||
|
MainViewState,
|
||||||
|
setMainViewStateAtom,
|
||||||
|
} from "@/_helpers/atoms/MainView.atom";
|
||||||
|
|
||||||
export default function useDeleteConversation() {
|
export default function useDeleteConversation() {
|
||||||
const [userConversations, setUserConversations] = useAtom(
|
const [userConversations, setUserConversations] = useAtom(
|
||||||
@ -23,14 +27,19 @@ export default function useDeleteConversation() {
|
|||||||
const activeConvoId = useAtomValue(getActiveConvoIdAtom);
|
const activeConvoId = useAtomValue(getActiveConvoIdAtom);
|
||||||
const setActiveConvoId = useSetAtom(setActiveConvoIdAtom);
|
const setActiveConvoId = useSetAtom(setActiveConvoIdAtom);
|
||||||
const deleteMessages = useSetAtom(deleteConversationMessage);
|
const deleteMessages = useSetAtom(deleteConversationMessage);
|
||||||
|
const setMainViewState = useSetAtom(setMainViewStateAtom);
|
||||||
|
|
||||||
const deleteConvo = async () => {
|
const deleteConvo = async () => {
|
||||||
if (activeConvoId) {
|
if (activeConvoId) {
|
||||||
try {
|
try {
|
||||||
await execute(DataService.DELETE_CONVERSATION, activeConvoId);
|
await execute(DataService.DELETE_CONVERSATION, activeConvoId);
|
||||||
setUserConversations(
|
const currentConversations = userConversations.filter(
|
||||||
userConversations.filter((c) => c.id !== activeConvoId)
|
(c) => c.id !== activeConvoId
|
||||||
);
|
);
|
||||||
|
setUserConversations(currentConversations);
|
||||||
|
if (currentConversations.length === 0) {
|
||||||
|
setMainViewState(MainViewState.Welcome);
|
||||||
|
}
|
||||||
deleteMessages(activeConvoId);
|
deleteMessages(activeConvoId);
|
||||||
setActiveConvoId(undefined);
|
setActiveConvoId(undefined);
|
||||||
setCurrentPrompt("");
|
setCurrentPrompt("");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user