fix(history): query chat session and history in sidebar (#400)
This commit is contained in:
committed by
GitHub
Unverified
parent
ed40a3b7f4
commit
ce0e5fd8af
@@ -22,6 +22,7 @@ import {
|
|||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { useSettingsStore } from '@/stores/settings';
|
import { useSettingsStore } from '@/stores/settings';
|
||||||
import { useChatStore } from '@/stores/chat';
|
import { useChatStore } from '@/stores/chat';
|
||||||
|
import { useGatewayStore } from '@/stores/gateway';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
|
||||||
@@ -113,6 +114,26 @@ export function Sidebar() {
|
|||||||
const switchSession = useChatStore((s) => s.switchSession);
|
const switchSession = useChatStore((s) => s.switchSession);
|
||||||
const newSession = useChatStore((s) => s.newSession);
|
const newSession = useChatStore((s) => s.newSession);
|
||||||
const deleteSession = useChatStore((s) => s.deleteSession);
|
const deleteSession = useChatStore((s) => s.deleteSession);
|
||||||
|
const loadSessions = useChatStore((s) => s.loadSessions);
|
||||||
|
const loadHistory = useChatStore((s) => s.loadHistory);
|
||||||
|
|
||||||
|
const gatewayStatus = useGatewayStore((s) => s.status);
|
||||||
|
const isGatewayRunning = gatewayStatus.state === 'running';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isGatewayRunning) return;
|
||||||
|
let cancelled = false;
|
||||||
|
const hasExistingMessages = useChatStore.getState().messages.length > 0;
|
||||||
|
(async () => {
|
||||||
|
await loadSessions();
|
||||||
|
if (cancelled) return;
|
||||||
|
await loadHistory(hasExistingMessages);
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [isGatewayRunning, loadHistory, loadSessions]);
|
||||||
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isOnChat = useLocation().pathname === '/';
|
const isOnChat = useLocation().pathname === '/';
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ export function Chat() {
|
|||||||
const streamingMessage = useChatStore((s) => s.streamingMessage);
|
const streamingMessage = useChatStore((s) => s.streamingMessage);
|
||||||
const streamingTools = useChatStore((s) => s.streamingTools);
|
const streamingTools = useChatStore((s) => s.streamingTools);
|
||||||
const pendingFinal = useChatStore((s) => s.pendingFinal);
|
const pendingFinal = useChatStore((s) => s.pendingFinal);
|
||||||
const loadHistory = useChatStore((s) => s.loadHistory);
|
|
||||||
const loadSessions = useChatStore((s) => s.loadSessions);
|
|
||||||
const sendMessage = useChatStore((s) => s.sendMessage);
|
const sendMessage = useChatStore((s) => s.sendMessage);
|
||||||
const abortRun = useChatStore((s) => s.abortRun);
|
const abortRun = useChatStore((s) => s.abortRun);
|
||||||
const clearError = useChatStore((s) => s.clearError);
|
const clearError = useChatStore((s) => s.clearError);
|
||||||
@@ -46,21 +44,12 @@ export function Chat() {
|
|||||||
// stay visible while fresh data loads in the background. This avoids
|
// stay visible while fresh data loads in the background. This avoids
|
||||||
// an unnecessary messages → spinner → messages flicker.
|
// an unnecessary messages → spinner → messages flicker.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isGatewayRunning) return;
|
|
||||||
let cancelled = false;
|
|
||||||
const hasExistingMessages = useChatStore.getState().messages.length > 0;
|
|
||||||
(async () => {
|
|
||||||
await loadSessions();
|
|
||||||
if (cancelled) return;
|
|
||||||
await loadHistory(hasExistingMessages);
|
|
||||||
})();
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
|
||||||
// If the user navigates away without sending any messages, remove the
|
// If the user navigates away without sending any messages, remove the
|
||||||
// empty session so it doesn't linger as a ghost entry in the sidebar.
|
// empty session so it doesn't linger as a ghost entry in the sidebar.
|
||||||
cleanupEmptySession();
|
cleanupEmptySession();
|
||||||
};
|
};
|
||||||
}, [isGatewayRunning, loadHistory, loadSessions, cleanupEmptySession]);
|
}, [cleanupEmptySession]);
|
||||||
|
|
||||||
// Auto-scroll on new messages, streaming, or activity changes
|
// Auto-scroll on new messages, streaming, or activity changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user