diff --git a/src/client/hooks/useSession.ts b/src/client/hooks/useSession.ts index 08e7e9b..1927de0 100644 --- a/src/client/hooks/useSession.ts +++ b/src/client/hooks/useSession.ts @@ -9,6 +9,7 @@ interface SessionState { sessionLoading: boolean; sessionError: string | null; loadSessions: () => Promise; + refreshSessions: () => Promise; loadSession: (id: string) => Promise; } @@ -21,11 +22,12 @@ export function useSession(): SessionState { const [sessionLoading, setSessionLoading] = useState(false); const [sessionError, setSessionError] = useState(null); - const loadSessions = useCallback(async () => { + const fetchSessions = useCallback(async (refresh = false) => { setSessionsLoading(true); setSessionsError(null); try { - const res = await fetch("/api/sessions"); + const url = refresh ? "/api/sessions?refresh=1" : "/api/sessions"; + const res = await fetch(url); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); setSessions(data.sessions); @@ -38,6 +40,9 @@ export function useSession(): SessionState { } }, []); + const loadSessions = useCallback(() => fetchSessions(false), [fetchSessions]); + const refreshSessions = useCallback(() => fetchSessions(true), [fetchSessions]); + const loadSession = useCallback(async (id: string) => { setSessionLoading(true); setSessionError(null); @@ -67,6 +72,7 @@ export function useSession(): SessionState { sessionLoading, sessionError, loadSessions, + refreshSessions, loadSession, }; } diff --git a/src/server/routes/sessions.ts b/src/server/routes/sessions.ts index 3a54c4a..6485dfa 100644 --- a/src/server/routes/sessions.ts +++ b/src/server/routes/sessions.ts @@ -19,8 +19,11 @@ async function getCachedSessions(): Promise { return cachedSessions; } -sessionsRouter.get("/", async (_req, res) => { +sessionsRouter.get("/", async (req, res) => { try { + if (req.query.refresh === "1") { + cacheTimestamp = 0; + } const sessions = await getCachedSessions(); res.json({ sessions }); } catch (err) {