Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ui/desktop/src/components/sessions/SessionListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ interface SearchContainerElement extends HTMLDivElement {
interface SessionListViewProps {
setView: (view: View, viewOptions?: ViewOptions) => void;
onSelectSession: (sessionId: string) => void;
selectedSessionId?: string | null;
}

const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSession }) => {
const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSession, selectedSessionId }) => {
const [sessions, setSessions] = useState<Session[]>([]);
const [filteredSessions, setFilteredSessions] = useState<Session[]>([]);
const [dateGroups, setDateGroups] = useState<DateGroup[]>([]);
Expand Down Expand Up @@ -278,6 +279,23 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
});
}, [debouncedSearchTerm, caseSensitive, sessions]);

// Scroll to the selected session when returning from session history view
useEffect(() => {
if (selectedSessionId && showContent && !isLoading) {
const sessionElement = containerRef.current?.querySelector(
`[session-item-id="${selectedSessionId}"]`
) as HTMLElement;

if (sessionElement) {
sessionElement.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest',
});
}
}
}, [selectedSessionId, showContent, isLoading]);

// Handle immediate search input (updates search term for debouncing)
const handleSearch = useCallback((term: string, caseSensitive: boolean) => {
setSearchTerm(term);
Expand Down Expand Up @@ -348,8 +366,9 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe

return (
<Card
onClick={handleCardClick}
onClick={() => onSelectSession(session.id)}
className="session-item h-full py-3 px-4 hover:shadow-default cursor-pointer transition-all duration-150 flex flex-col justify-between relative group"
session-item-id={session.id}
>
<button
onClick={handleEditClick}
Expand Down
16 changes: 12 additions & 4 deletions ui/desktop/src/components/sessions/SessionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface SessionsViewProps {

const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
const [selectedSession, setSelectedSession] = useState<SessionDetails | null>(null);
const [showSessionHistory, setShowSessionHistory] = useState(false);
const [isLoadingSession, setIsLoadingSession] = useState(false);
const [error, setError] = useState<string | null>(null);
const [initialSessionId, setInitialSessionId] = useState<string | null>(null);
Expand All @@ -20,6 +21,8 @@ const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
const loadSessionDetails = async (sessionId: string) => {
setIsLoadingSession(true);
setError(null);
setShowSessionHistory(true);

try {
const sessionDetails = await fetchSessionDetails(sessionId);
setSelectedSession(sessionDetails);
Expand All @@ -28,6 +31,7 @@ const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
setError('Failed to load session details. Please try again later.');
// Keep the selected session null if there's an error
setSelectedSession(null);
setShowSessionHistory(false);

const errorMessage = err instanceof Error ? err.message : String(err);
toastError({
Expand Down Expand Up @@ -59,7 +63,7 @@ const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
}, [location.state, handleSelectSession]);

const handleBackToSessions = () => {
setSelectedSession(null);
setShowSessionHistory(false);
setError(null);
};

Expand All @@ -69,9 +73,9 @@ const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
}
};

// If we're loading an initial session or have a selected session, show the session history view
// If we're loading an initial session or have a selected showSessionHistory, show the session history view
// Otherwise, show the sessions list view
return selectedSession || (isLoadingSession && initialSessionId) ? (
return (showSessionHistory && selectedSession) || (isLoadingSession && initialSessionId) ? (
<SessionHistoryView
session={
selectedSession || {
Expand All @@ -91,7 +95,11 @@ const SessionsView: React.FC<SessionsViewProps> = ({ setView }) => {
onRetry={handleRetryLoadSession}
/>
) : (
<SessionListView setView={setView} onSelectSession={handleSelectSession} />
<SessionListView
setView={setView}
onSelectSession={handleSelectSession}
selectedSessionId={selectedSession?.session_id ?? null}
/>
);
};

Expand Down
Loading