feat: relative timestamps, message preview, and recency sort in sidebar
- Show relative time (2m, 3h, 1d) next to each session name - Display last message preview below session name (truncated to 80 chars) - Sort sessions by most recently updated (within pinned/unpinned groups) - Map updatedAt and lastMessagePreview from gateway sessions.list response
This commit is contained in:
19
src/lib/relativeTime.ts
Normal file
19
src/lib/relativeTime.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Format a timestamp as a short relative time string (e.g. "2m", "3h", "1d").
|
||||
* Returns null for invalid/missing timestamps.
|
||||
*/
|
||||
export function relativeTime(ts: number | undefined): string | null {
|
||||
if (!ts) return null;
|
||||
const now = Date.now();
|
||||
const diff = Math.max(0, now - ts);
|
||||
const seconds = Math.floor(diff / 1000);
|
||||
if (seconds < 60) return '<1m';
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
if (minutes < 60) return `${minutes}m`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours}h`;
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days < 30) return `${days}d`;
|
||||
const months = Math.floor(days / 30);
|
||||
return `${months}mo`;
|
||||
}
|
||||
Reference in New Issue
Block a user