Skip to content

Commit aa4674e

Browse files
committed
feat(ui): display time in graph selector
1 parent e51472b commit aa4674e

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

ui-ssr/src/components/circuits/graph-selector.tsx

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ import type { CircuitListItem } from '@/api/circuits'
55
import { deleteCircuit } from '@/api/circuits'
66
import { cn } from '@/lib/utils'
77

8+
function formatRelativeTime(dateString: string): string {
9+
const date = new Date(dateString)
10+
const now = new Date()
11+
const diffMs = now.getTime() - date.getTime()
12+
const diffSeconds = Math.floor(diffMs / 1000)
13+
const diffMinutes = Math.floor(diffSeconds / 60)
14+
const diffHours = Math.floor(diffMinutes / 60)
15+
const diffDays = Math.floor(diffHours / 24)
16+
17+
if (diffSeconds < 60) {
18+
return 'just now'
19+
}
20+
if (diffMinutes < 60) {
21+
return `${diffMinutes} minute${diffMinutes === 1 ? '' : 's'} ago`
22+
}
23+
if (diffHours < 24) {
24+
return `${diffHours} hour${diffHours === 1 ? '' : 's'} ago`
25+
}
26+
if (diffDays < 7) {
27+
return `${diffDays} day${diffDays === 1 ? '' : 's'} ago`
28+
}
29+
30+
return date.toLocaleDateString()
31+
}
32+
833
interface GraphSelectorProps {
934
circuits: CircuitListItem[]
1035
selectedCircuitId: string
@@ -75,9 +100,15 @@ export function GraphSelector({
75100
? `${selectedCircuit.prompt.slice(0, 60)}...`
76101
: selectedCircuit.prompt}
77102
</span>
78-
<span className="text-xs text-slate-500 truncate w-full">
79-
{selectedCircuit.name || selectedCircuit.id}
80-
</span>
103+
<div className="flex items-center gap-2 text-xs text-slate-500 truncate w-full">
104+
<span className="truncate">
105+
{selectedCircuit.name || selectedCircuit.id}
106+
</span>
107+
<span className="shrink-0">·</span>
108+
<span className="shrink-0">
109+
{formatRelativeTime(selectedCircuit.createdAt)}
110+
</span>
111+
</div>
81112
</div>
82113
) : (
83114
<span className="text-slate-500">Select a graph</span>
@@ -115,9 +146,13 @@ export function GraphSelector({
115146
? `${c.prompt.slice(0, 50)}...`
116147
: c.prompt}
117148
</span>
118-
<span className="text-xs text-slate-500 truncate">
119-
{c.name || c.id}
120-
</span>
149+
<div className="flex items-center gap-2 text-xs text-slate-500">
150+
<span className="truncate">{c.name || c.id}</span>
151+
<span className="shrink-0">·</span>
152+
<span className="shrink-0">
153+
{formatRelativeTime(c.createdAt)}
154+
</span>
155+
</div>
121156
</div>
122157
<button
123158
type="button"

0 commit comments

Comments
 (0)