auto-refresh teamsbot session list every 10s to catch new/changed sessions
All checks were successful
Deploy Nyla Frontend to Production / deploy (push) Successful in 45s
Deploy Nyla Frontend to Integration / deploy (push) Successful in 1m27s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ValueOn AG 2026-05-29 00:54:29 +02:00
parent 6c319a4170
commit 7da7ad5041

View file

@ -436,6 +436,28 @@ export const TeamsbotSessionView: React.FC = () => {
});
}, [session?.id, session?.status, session?.botName, session?.startedAt, session?.endedAt]);
// Periodically refresh the full session list to discover new/changed/ended sessions.
useEffect(() => {
if (!instanceId) return;
const listPollRef = setInterval(async () => {
try {
const listResult = await teamsbotApi.listSessions(instanceId, true);
const fresh = listResult.sessions || [];
setAllSessions((prev) => {
if (prev.length !== fresh.length) return fresh;
const changed = fresh.some((s, i) => {
const old = prev[i];
return !old || old.id !== s.id || old.status !== s.status
|| old.endedAt !== s.endedAt || old.startedAt !== s.startedAt;
});
return changed ? fresh : prev;
});
if (noSessions && fresh.length > 0) setNoSessions(false);
} catch { /* ignore */ }
}, 10_000);
return () => clearInterval(listPollRef);
}, [instanceId, noSessions]);
// Polling: while joining/pending, poll even if SSE is connected (status may not arrive on stream).
// For active-only, poll only when SSE is down (previous behavior).
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);