refactor: Directly add new chat session to state upon creation (#62)
This commit is contained in:
@@ -423,8 +423,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
|||||||
// Generate a new unique session key and switch to it
|
// Generate a new unique session key and switch to it
|
||||||
const prefix = getCanonicalPrefixFromSessions(get().sessions) ?? DEFAULT_CANONICAL_PREFIX;
|
const prefix = getCanonicalPrefixFromSessions(get().sessions) ?? DEFAULT_CANONICAL_PREFIX;
|
||||||
const newKey = `${prefix}:session-${Date.now()}`;
|
const newKey = `${prefix}:session-${Date.now()}`;
|
||||||
set({
|
const newSessionEntry: ChatSession = { key: newKey, displayName: newKey };
|
||||||
|
set((s) => ({
|
||||||
currentSessionKey: newKey,
|
currentSessionKey: newKey,
|
||||||
|
sessions: [...s.sessions, newSessionEntry],
|
||||||
messages: [],
|
messages: [],
|
||||||
streamingText: '',
|
streamingText: '',
|
||||||
streamingMessage: null,
|
streamingMessage: null,
|
||||||
@@ -433,9 +435,7 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
|||||||
error: null,
|
error: null,
|
||||||
pendingFinal: false,
|
pendingFinal: false,
|
||||||
lastUserMessageAt: null,
|
lastUserMessageAt: null,
|
||||||
});
|
}));
|
||||||
// Reload sessions list to include the new one after first message
|
|
||||||
get().loadSessions();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// ── Load chat history ──
|
// ── Load chat history ──
|
||||||
|
|||||||
Reference in New Issue
Block a user