diff --git a/src/pages/views/teamsbot/TeamsbotSessionView.tsx b/src/pages/views/teamsbot/TeamsbotSessionView.tsx index 80b70a5..1e3f562 100644 --- a/src/pages/views/teamsbot/TeamsbotSessionView.tsx +++ b/src/pages/views/teamsbot/TeamsbotSessionView.tsx @@ -15,6 +15,7 @@ export const TeamsbotSessionView: React.FC = () => { const sessionId = searchParams.get('sessionId') || ''; const [session, setSession] = useState(null); + const [allSessions, setAllSessions] = useState([]); const [transcripts, setTranscripts] = useState([]); const [botResponses, setBotResponses] = useState([]); const [loading, setLoading] = useState(true); @@ -32,19 +33,23 @@ export const TeamsbotSessionView: React.FC = () => { setLoading(true); setNoSessions(false); + // Always load the full session list for the switcher + const listResult = await teamsbotApi.listSessions(instanceId, true); + const sessions = listResult.sessions || []; + setAllSessions(sessions); + let targetSessionId = sessionId; - // No sessionId in URL -> find the most recent session + // No sessionId in URL -> find the most recent active or latest session if (!targetSessionId) { - const listResult = await teamsbotApi.listSessions(instanceId, true); - const sessions = listResult.sessions || []; if (sessions.length === 0) { setNoSessions(true); setLoading(false); return; } - // Pick the most recent (first in list, sorted by creation date desc) - targetSessionId = sessions[0].id; + // Prefer active sessions, then most recent + const activeSession = sessions.find(s => ['active', 'joining', 'pending'].includes(s.status)); + targetSessionId = activeSession ? activeSession.id : sessions[0].id; setSearchParams({ sessionId: targetSessionId }, { replace: true }); } @@ -178,8 +183,37 @@ export const TeamsbotSessionView: React.FC = () => { ); if (!session) return
Sitzung nicht gefunden
; + const _switchSession = (newSessionId: string) => { + setSearchParams({ sessionId: newSessionId }); + }; + return (
+ {/* Session Switcher (if multiple sessions exist) */} + {allSessions.length > 1 && ( +
+ {allSessions.map((s) => ( + + ))} +
+ )} + {/* Session Header */}