Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions ui/desktop/src/acp/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface SessionListItem {
modelId?: string;
userSetName?: boolean;
hasRecipe?: boolean;
sessionType?: Session['session_type'];
}

export interface SessionListPage {
Expand Down Expand Up @@ -128,6 +129,7 @@ function sessionInfoToListItem(s: SessionInfo): SessionListItem {
modelId: meta.modelId,
userSetName: meta.userSetName,
hasRecipe: meta.hasRecipe,
sessionType: meta.sessionType,
};
}

Expand Down
115 changes: 105 additions & 10 deletions ui/desktop/src/components/sessions/SessionListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
LoaderCircle,
ExternalLink,
Copy,
ChevronDown,
ChevronRight,
Clock,
} from 'lucide-react';
import { Card } from '../ui/card';
import { Button } from '../ui/button';
Expand Down Expand Up @@ -163,6 +166,14 @@ const i18n = defineMessages({
'Anyone with this link can fetch and decrypt the session. Treat it like a secret.',
},
close: { id: 'sessions.close', defaultMessage: 'Close' },
scheduledJobs: {
id: 'sessions.scheduledJobs',
defaultMessage: 'Scheduled Jobs',
},
scheduledJobsCount: {
id: 'sessions.scheduledJobsCount',
defaultMessage: '{count} {count, plural, one {job} other {jobs}}',
},
});

interface EditSessionModalProps {
Expand Down Expand Up @@ -314,6 +325,7 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
const [error, setError] = useState<string | null>(null);

const [visibleGroupsCount, setVisibleGroupsCount] = useState(15);
const [isScheduledExpanded, setIsScheduledExpanded] = useState(false);

// Edit modal state
const [showEditModal, setShowEditModal] = useState(false);
Expand Down Expand Up @@ -343,9 +355,20 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe

const fileInputRef = useRef<HTMLInputElement>(null);

const memoizedAllDateGroups = useMemo(() => {
if (sessions.length > 0) {
return groupSessionsByDate(sessions);
}
return [];
}, [sessions]);

const activeDateGroups = useMemo(() => {
return debouncedSearchTerm.length > 0 ? memoizedAllDateGroups : dateGroups;
}, [debouncedSearchTerm, memoizedAllDateGroups, dateGroups]);

const visibleDateGroups = useMemo(() => {
return dateGroups.slice(0, visibleGroupsCount);
}, [dateGroups, visibleGroupsCount]);
return activeDateGroups.slice(0, visibleGroupsCount);
}, [activeDateGroups, visibleGroupsCount]);

const previousSearchTermRef = useRef('');
useEffect(() => {
Expand All @@ -354,11 +377,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
previousSearchTermRef.current = debouncedSearchTerm;

if (isSearching) {
setVisibleGroupsCount(dateGroups.length);
setVisibleGroupsCount(memoizedAllDateGroups.length);
} else if (wasSearching) {
setVisibleGroupsCount(15);
}
}, [debouncedSearchTerm, dateGroups.length]);
}, [debouncedSearchTerm, memoizedAllDateGroups.length]);

const loadRemainingSessionPages = useCallback(
async (initialCursor: string, loadId: number, keyword?: string) => {
Expand Down Expand Up @@ -437,11 +460,11 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe

if (scrollHeight - scrollTop - clientHeight >= threshold) return;

if (visibleGroupsCount < dateGroups.length) {
setVisibleGroupsCount((prev) => Math.min(prev + 5, dateGroups.length));
if (visibleGroupsCount < activeDateGroups.length) {
setVisibleGroupsCount((prev) => Math.min(prev + 5, activeDateGroups.length));
}
},
[visibleGroupsCount, dateGroups.length]
[visibleGroupsCount, activeDateGroups.length]
);

useEffect(() => {
Expand Down Expand Up @@ -474,13 +497,34 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
return () => void 0;
}, [isLoading, showSkeleton]);

// Split sessions into human-created and scheduled job sessions
const { humanSessions, scheduledSessions } = useMemo(() => {
const human: SessionListItem[] = [];
const scheduled: SessionListItem[] = [];
for (const s of sessions) {
if (s.sessionType === 'scheduled') {
scheduled.push(s);
} else {
human.push(s);
}
}
return { humanSessions: human, scheduledSessions: scheduled };
}, [sessions]);

// Memoize date groups calculation to prevent unnecessary recalculations
const memoizedDateGroups = useMemo(() => {
if (sessions.length > 0) {
return groupSessionsByDate(sessions);
if (humanSessions.length > 0) {
return groupSessionsByDate(humanSessions);
}
return [];
}, [sessions]);
}, [humanSessions]);

const memoizedScheduledDateGroups = useMemo(() => {
if (scheduledSessions.length > 0) {
return groupSessionsByDate(scheduledSessions);
}
return [];
}, [scheduledSessions]);

// Update date groups when filtered sessions change
useEffect(() => {
Expand Down Expand Up @@ -972,6 +1016,57 @@ const SessionListView: React.FC<SessionListViewProps> = React.memo(({ onSelectSe
</div>
))}

{!debouncedSearchTerm && memoizedScheduledDateGroups.length > 0 && (
<div className="space-y-4">
<button
onClick={() => setIsScheduledExpanded((v) => !v)}
className="sticky top-0 z-10 w-full flex items-center justify-between bg-background-primary/95 backdrop-blur-sm py-2 px-1 rounded-lg hover:bg-background-secondary transition-colors cursor-pointer"
Comment on lines +1021 to +1025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expose the accordion state to assistive technology

For screen-reader users, expanding this disclosure leaves the button's accessible name unchanged and exposes no expanded/collapsed state, so they cannot determine whether the scheduled sessions are currently visible. Add an aria-expanded value tied to isScheduledExpanded (and preferably aria-controls targeting the collapsible region).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push. The disclosure button now exposes aria-expanded and references the collapsible region through aria-controls.

>
<div className="flex items-center gap-2">
<Clock className="w-4 h-4 text-text-secondary" />
<h2 className="text-text-secondary font-medium">
{intl.formatMessage(i18n.scheduledJobs)}
</h2>
<span className="text-xs text-text-tertiary bg-background-secondary px-2 py-0.5 rounded-full">
{intl.formatMessage(i18n.scheduledJobsCount, { count: scheduledSessions.length })}
</span>
</div>
{isScheduledExpanded ? (
<ChevronDown className="w-4 h-4 text-text-secondary" />
) : (
<ChevronRight className="w-4 h-4 text-text-secondary" />
)}
</button>

{isScheduledExpanded && (
<div className="space-y-8">
{memoizedScheduledDateGroups.map((group) => (
Comment on lines +1043 to +1045

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep scheduled runs from blocking older human sessions

When the history spans more than the initial 15 human date groups and this accordion is expanded, this branch renders every scheduled group after only those 15 groups. Because handleScroll adds further human groups only when the viewport is within 200px of the absolute bottom, users must scroll through the entire scheduled history before older human conversations are loaded, which defeats the purpose of keeping scheduled runs out of their way. Load the remaining human groups independently or place the expanded content where it cannot gate the human-history pagination.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b56f75e. The scheduled accordion is now rendered only after every human date group is visible, so expanded scheduled history cannot block pagination to older human sessions.

<div key={group.label} className="space-y-4">
<div className="sticky top-0 z-10 bg-background-primary/95 backdrop-blur-sm">
<h2 className="text-text-secondary">{group.label}</h2>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4">
{group.sessions.map((session) => (
<SessionItem
key={session.id}
session={session}
onEditClick={handleEditSession}
onDuplicateClick={handleDuplicateSession}
onDeleteClick={handleDeleteSession}
onExportClick={handleExportSession}
onShareClick={handleShareSessionNostr}
onOpenInNewWindow={handleOpenInNewWindow}
isSharing={sharingSessionId === session.id}
/>
))}
</div>
</div>
))}
</div>
)}
</div>
)}

{isPrefetchingSessions && (
<div className="flex justify-center py-8">
<div className="flex items-center space-x-2 text-text-secondary">
Expand Down
6 changes: 6 additions & 0 deletions ui/desktop/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4654,5 +4654,11 @@
},
"userMessage.removeImageFromEdit": {
"defaultMessage": "Remove image from message"
},
"sessions.scheduledJobs": {
"defaultMessage": "Scheduled Jobs"
},
"sessions.scheduledJobsCount": {
"defaultMessage": "{count} {count, plural, one {job} other {jobs}}"
}
}
Loading