fix: ensure latest session always displays in sidebar (#7489)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import { useNavigate, useLocation, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useLocation, useSearchParams } from 'react-router-dom';
|
||||||
import { listSessions } from '../api';
|
import { getSession, listSessions } from '../api';
|
||||||
import { useChatContext } from '../contexts/ChatContext';
|
import { useChatContext } from '../contexts/ChatContext';
|
||||||
import { useConfig } from '../components/ConfigContext';
|
import { useConfig } from '../components/ConfigContext';
|
||||||
import { useNavigation } from './useNavigation';
|
import { useNavigation } from './useNavigation';
|
||||||
@@ -66,6 +66,19 @@ export function useNavigationSessions(options: UseNavigationSessionsOptions = {}
|
|||||||
}
|
}
|
||||||
}, [fetchOnMount, fetchSessions]);
|
}, [fetchOnMount, fetchSessions]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!activeSessionId) return;
|
||||||
|
if (recentSessions.some((s) => s.id === activeSessionId)) return;
|
||||||
|
|
||||||
|
getSession({ path: { session_id: activeSessionId }, throwOnError: false }).then((response) => {
|
||||||
|
if (!response.data) return;
|
||||||
|
setRecentSessions((prev) => {
|
||||||
|
if (prev.some((s) => s.id === activeSessionId)) return prev;
|
||||||
|
return [response.data as Session, ...prev].slice(0, MAX_RECENT_SESSIONS);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [activeSessionId, recentSessions]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let pollingTimeouts: ReturnType<typeof setTimeout>[] = [];
|
let pollingTimeouts: ReturnType<typeof setTimeout>[] = [];
|
||||||
let isPolling = false;
|
let isPolling = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user