diff --git a/app/store/chat.ts b/app/store/chat.ts index ed9bbd670..07bfae676 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -212,7 +212,7 @@ export const useChatStore = create()( // On the desktop, the deleted session index may not be the current session index const seletedSessionIndex = get().currentSessionIndex; - const isLastSession = get().sessions.length === 1; + const isLastSession = get().sessions.length === 1 ? 1 : 0; if (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) { get().removeSession(index); @@ -221,13 +221,12 @@ export const useChatStore = create()( { text: Locale.Home.Revert, onClick() { + const sessions = get().sessions; + // if the deleted session is the only session in sessions array, + // we should delete the empty session first before inserting the deleted session + sessions.splice(index, isLastSession, deletedSession); set(() => ({ - sessions: get() - .sessions.slice(0, index) - .concat([deletedSession]) - .concat( - get().sessions.slice(index + Number(isLastSession)), - ), + sessions: sessions, currentSessionIndex: seletedSessionIndex, })); },