/** * @license * Copyright 2025 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ import React from 'react'; import { getTimeAgo, groupSessionsByDate, } from '../../utils/sessionGrouping.js'; import { SearchIcon } from '../icons/index.js'; interface SessionSelectorProps { visible: boolean; sessions: Array>; currentSessionId: string | null; searchQuery: string; onSearchChange: (query: string) => void; onSelectSession: (sessionId: string) => void; onClose: () => void; hasMore?: boolean; isLoading?: boolean; onLoadMore?: () => void; } /** * Session selector component * Display session list and support search and selection */ export const SessionSelector: React.FC = ({ visible, sessions, currentSessionId, searchQuery, onSearchChange, onSelectSession, onClose, hasMore = false, isLoading = false, onLoadMore, }) => { if (!visible) { return null; } const hasNoSessions = sessions.length === 0; return ( <>
e.stopPropagation()} > {/* Search Box */}
onSearchChange(e.target.value)} />
{/* Session List with Grouping */}
{ const el = e.currentTarget; const distanceToBottom = el.scrollHeight - (el.scrollTop + el.clientHeight); if (distanceToBottom < 48 && hasMore && !isLoading) { onLoadMore?.(); } }} > {hasNoSessions ? (
{searchQuery ? 'No matching sessions' : 'No sessions available'}
) : ( groupSessionsByDate(sessions).map((group) => (
{group.label}
{group.sessions.map((session) => { const sessionId = (session.id as string) || (session.sessionId as string) || ''; const title = (session.title as string) || (session.name as string) || 'Untitled'; const lastUpdated = (session.lastUpdated as string) || (session.startTime as string) || ''; const isActive = sessionId === currentSessionId; return ( ); })}
)) )} {hasMore && (
{isLoading ? 'Loading…' : ''}
)}
); };