diff --git a/src/components/HistorySidebar.tsx b/src/components/HistorySidebar.tsx index 569f9c0..ec4f25a 100644 --- a/src/components/HistorySidebar.tsx +++ b/src/components/HistorySidebar.tsx @@ -67,10 +67,12 @@ export function HistorySidebar({ }: HistorySidebarProps) { const bodyRef = useRef(null); const [pendingDeleteId, setPendingDeleteId] = useState(null); + const [pendingSelectId, setPendingSelectId] = useState(null); useEffect(() => { if (open) { setPendingDeleteId(null); + setPendingSelectId(null); } }, [open, sessions.length]); @@ -84,6 +86,7 @@ export function HistorySidebar({ }, [hasMore, loading, loadingMore, onLoadMore]); const handleDeleteClick = useCallback((sessionId: string) => { + setPendingSelectId(null); setPendingDeleteId(sessionId); }, []); @@ -99,6 +102,24 @@ export function HistorySidebar({ setPendingDeleteId(null); }, []); + const handleSelectClick = useCallback( + (sessionId: string) => { + if (pendingDeleteId === sessionId) return; + if (activeSessionId === sessionId) { + setPendingSelectId(null); + onSelect(sessionId); + return; + } + if (pendingSelectId === sessionId) { + setPendingSelectId(null); + onSelect(sessionId); + return; + } + setPendingSelectId(sessionId); + }, + [activeSessionId, onSelect, pendingDeleteId, pendingSelectId], + ); + if (!open) return null; const sessionGroups = groupSessionsByDate(sessions); @@ -145,17 +166,21 @@ export function HistorySidebar({ {group.sessions.map((item) => { const label = getSessionListLabel(item); const isPending = pendingDeleteId === item.id; + const isPendingSelect = pendingSelectId === item.id; return (
  • {isPending ? (
    diff --git a/src/hooks/useTKMindChat.ts b/src/hooks/useTKMindChat.ts index 017d190..a536c42 100644 --- a/src/hooks/useTKMindChat.ts +++ b/src/hooks/useTKMindChat.ts @@ -883,29 +883,28 @@ export function useTKMindChat( setPendingTool(null); activeRequestId.current = null; - const resumed = options?.skipResume - ? (options.seedSession ?? null) - : await withTransientConnectRetry(() => - resumeSession(sessionId, { - skipReconcile: options?.skipReconcile ?? false, - }), - ); - if (token !== connectTokenRef.current) return; - const knownSession = sessionsRef.current.find((s) => s.id === sessionId); const hints = knownSession ? { messageCount: knownSession.message_count, updatedAt: knownSession.updated_at } : undefined; - const { session: detail, messages: history, page } = await withTransientConnectRetry(() => + const detailPromise = withTransientConnectRetry(() => loadSessionDetail(sessionId, hints, { before: 0, limit: appConfig.sessionMessagePageSize, }), ); + const resumedPromise = options?.skipResume + ? Promise.resolve(options.seedSession ?? null) + : withTransientConnectRetry(() => + resumeSession(sessionId, { + skipReconcile: options?.skipReconcile ?? false, + }), + ); + const { session: detail, messages: history, page } = await detailPromise; if (token !== connectTokenRef.current) return; writeStoredSessionId(userRef.current?.id, sessionId); - setSession({ ...detail, ...(resumed ?? {}), id: sessionId }); + setSession((current) => (current?.id === sessionId ? { ...detail, ...current, id: sessionId } : { ...detail, id: sessionId })); messagesRef.current = history; messageHistoryLoadedCountRef.current = history.length; messageHistoryTotalRef.current = Math.max(Number(page.total ?? history.length), history.length); @@ -913,6 +912,9 @@ export function useTKMindChat( setMessageHistoryHasMore(messageHistoryHasMoreRef.current); setMessageHistoryTotal(messageHistoryTotalRef.current); setMessages(history); + const resumed = await resumedPromise; + if (token !== connectTokenRef.current) return; + setSession({ ...detail, ...(resumed ?? {}), id: sessionId }); setChatState('idle'); setSessions((prev) => prependUnique(prev, toSessionSummary({ ...detail, ...(resumed ?? {}), id: sessionId })),