Skip to content

Commit

Permalink
fix: rerender chat component
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogtiti committed Nov 11, 2024
1 parent 38fa305 commit 790adb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,6 @@ function _Chat() {

export function Chat() {
const chatStore = useChatStore();
const sessionIndex = chatStore.currentSessionIndex;
return <_Chat key={sessionIndex}></_Chat>;
const forceUpdateKey = chatStore.forceUpdateKey;
return <_Chat key={forceUpdateKey}></_Chat>;
}
7 changes: 7 additions & 0 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const DEFAULT_CHAT_STATE = {
sessions: [createEmptySession()],
currentSessionIndex: 0,
lastInput: "",
forceUpdateKey: Date.now(),
};

export const useChatStore = createPersistStore(
Expand Down Expand Up @@ -225,19 +226,22 @@ export const useChatStore = createPersistStore(
set((state) => ({
currentSessionIndex: 0,
sessions: [newSession, ...state.sessions],
forceUpdateKey: Date.now(),
}));
},

clearSessions() {
set(() => ({
sessions: [createEmptySession()],
currentSessionIndex: 0,
forceUpdateKey: Date.now(),
}));
},

selectSession(index: number) {
set({
currentSessionIndex: index,
forceUpdateKey: Date.now(),
});
},

Expand All @@ -262,6 +266,7 @@ export const useChatStore = createPersistStore(
return {
currentSessionIndex: newIndex,
sessions: newSessions,
forceUpdateKey: Date.now(),
};
});
},
Expand All @@ -286,6 +291,7 @@ export const useChatStore = createPersistStore(
set((state) => ({
currentSessionIndex: 0,
sessions: [session].concat(state.sessions),
forceUpdateKey: Date.now(),
}));
},

Expand Down Expand Up @@ -325,6 +331,7 @@ export const useChatStore = createPersistStore(
set(() => ({
currentSessionIndex: nextIndex,
sessions,
forceUpdateKey: Date.now(),
}));

showToast(
Expand Down

0 comments on commit 790adb2

Please sign in to comment.