mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-11 20:43:42 +08:00
更新 revert 操作的实现逻辑
通过 ... 的语法创建一个新的 ChatSession[] 副本,在副本上执行 splice 操作,避免直接修改状态
This commit is contained in:
@@ -221,14 +221,16 @@ export const useChatStore = create<ChatStore>()(
|
||||
{
|
||||
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: sessions,
|
||||
currentSessionIndex: seletedSessionIndex,
|
||||
}));
|
||||
set((state) => {
|
||||
const newSessions = [...state.sessions];
|
||||
// if the deleted session is the only session in sessions array,
|
||||
// we should delete the empty session first before inserting the deleted session
|
||||
newSessions.splice(index, isLastSession, deletedSession);
|
||||
return {
|
||||
sessions: newSessions,
|
||||
currentSessionIndex: seletedSessionIndex,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
5000,
|
||||
|
Reference in New Issue
Block a user