forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecapDetailPanel.tsx
More file actions
719 lines (655 loc) · 25.1 KB
/
Copy pathRecapDetailPanel.tsx
File metadata and controls
719 lines (655 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
'use client';
import { useState, useEffect, useMemo } from 'react';
import { useRouter } from '@tschk/moonshine-next/navigation';
import { motion } from 'framer-motion';
import {
Calendar,
Sparkles,
CheckSquare,
Lightbulb,
MapPin,
MessageSquare,
Clock,
Loader2,
Maximize2,
} from 'lucide-react';
import dynamic from '@tschk/moonshine-next/dynamic';
// Dynamically import LocationMap to avoid SSR issues with Leaflet
const LocationMap = dynamic(() => import('./sections/LocationMap'), {
ssr: false,
loading: () => (
<div className="h-full bg-bg-tertiary animate-pulse flex items-center justify-center">
<MapPin className="w-8 h-8 text-text-quaternary" />
</div>
),
});
import { cn } from '@/lib/utils';
import { getDailySummary, getConversation } from '@/lib/api';
import type { DailySummary, LocationPin } from '@/types/recap';
import { HighlightsSection } from './sections/HighlightsSection';
import { TasksSection } from './sections/TasksSection';
import { InsightsSection } from './sections/InsightsSection';
import { LocationsSection } from './sections/LocationsSection';
import { ConversationPreviewPanel } from './ConversationPreviewPanel';
interface RecapDetailPanelProps {
recapId: string;
recap?: DailySummary | null;
onBack?: () => void;
onConversationClick?: (conversationId: string) => void;
}
type RecapTab = 'recap' | 'journey';
// Format date for display (parse as local date, not UTC)
function formatRecapDate(dateString: string): string {
// Parse YYYY-MM-DD as local date to avoid timezone shift
const [year, month, day] = dateString.split('-').map(Number);
const date = new Date(year, month - 1, day);
return date.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
});
}
// Format duration in minutes to human-readable
function formatDuration(minutes: number): string {
if (minutes < 60) {
return `${minutes}m`;
}
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;
}
// Format time for journey timeline (12-hour AM/PM format)
function formatJourneyTime(timeString: string): string {
if (!timeString) return '';
// Try parsing as full date/time first
let date = new Date(timeString);
// If invalid, try parsing as time-only string (e.g., "14:30" or "14:30:00")
if (isNaN(date.getTime())) {
const timeMatch = timeString.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
if (timeMatch) {
const [, hours, minutes] = timeMatch;
date = new Date();
date.setHours(parseInt(hours, 10), parseInt(minutes, 10), 0, 0);
} else {
return timeString; // Fallback to raw string
}
}
return date.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
}
// Journey Timeline component for expanded map view
interface JourneyTimelineProps {
locations: LocationPin[];
onConversationClick?: (conversationId: string) => void;
currentIndex?: number; // -1 = show all, >=0 = progressive display
onLocationClick?: (index: number) => void; // Click to jump to location
}
// Parse time string to comparable value (handles both full datetime and time-only strings)
function parseTimeValue(timeString: string): number {
if (!timeString) return 0;
// Try parsing as full date/time first
const date = new Date(timeString);
if (!isNaN(date.getTime())) {
return date.getTime();
}
// Try parsing as time-only string (e.g., "14:30" or "14:30:00")
const timeMatch = timeString.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
if (timeMatch) {
const [, hours, minutes, seconds = '0'] = timeMatch;
// Convert to seconds since midnight for comparison
return (
parseInt(hours, 10) * 3600 + parseInt(minutes, 10) * 60 + parseInt(seconds, 10)
);
}
return 0;
}
function JourneyTimeline({
locations,
onConversationClick,
currentIndex = -1,
onLocationClick,
}: JourneyTimelineProps) {
const [conversationCache, setConversationCache] = useState<
Record<string, { title: string; emoji: string }>
>({});
const [loading, setLoading] = useState(true);
// Determine if we're in progressive mode
const isProgressiveMode = currentIndex >= 0;
// Sort locations by time (memoized to avoid infinite re-renders)
const sortedLocations = useMemo(() => {
return [...locations].sort((a, b) => parseTimeValue(a.time) - parseTimeValue(b.time));
}, [locations]);
// Fetch conversation details
useEffect(() => {
const fetchConversations = async () => {
const uniqueIds = [
...new Set(
sortedLocations
.map((loc) => loc.conversation_id)
.filter((id): id is string => !!id),
),
];
if (uniqueIds.length === 0) {
setLoading(false);
return;
}
const results = await Promise.all(
uniqueIds.map(async (id) => {
try {
const conv = await getConversation(id);
return { id, title: conv.structured.title, emoji: conv.structured.emoji };
} catch {
return null;
}
}),
);
const cache: Record<string, { title: string; emoji: string }> = {};
results.forEach((r) => {
if (r) cache[r.id] = { title: r.title ?? '', emoji: r.emoji ?? '' };
});
setConversationCache(cache);
setLoading(false);
};
fetchConversations();
}, [sortedLocations]);
const getLocationDisplay = (loc: LocationPin) => {
if (loc.conversation_id && conversationCache[loc.conversation_id]) {
return conversationCache[loc.conversation_id];
}
return { title: loc.address, emoji: '📍' };
};
return (
<div className="h-full flex flex-col">
{/* Header */}
<div className="p-4 border-b border-white/[0.04]">
<h4 className="text-sm font-medium text-text-primary flex items-center gap-2">
<Clock className="w-4 h-4 text-white" />
Your Journey
</h4>
</div>
{/* Timeline list */}
<div className="flex-1 overflow-y-auto p-4">
{loading ? (
<div className="space-y-3">
{[...Array(Math.min(sortedLocations.length, 5))].map((_, i) => (
<div key={i} className="flex gap-3 animate-pulse">
<div className="w-8 h-8 bg-bg-tertiary rounded-full" />
<div className="flex-1 space-y-1">
<div className="h-3 bg-bg-tertiary rounded w-16" />
<div className="h-4 bg-bg-tertiary rounded w-32" />
</div>
</div>
))}
</div>
) : (
<div className="relative">
{/* Vertical line connecting all items */}
<div className="absolute left-4 top-4 bottom-4 w-px bg-white/20" />
<div className="space-y-4">
{sortedLocations.map((loc, idx) => {
const display = getLocationDisplay(loc);
// In progressive mode, determine visibility
const isPast = !isProgressiveMode || idx < currentIndex;
const isCurrent = isProgressiveMode && idx === currentIndex;
const isFuture = isProgressiveMode && idx > currentIndex;
// Hide future items during playback
if (isFuture) return null;
return (
<motion.div
key={idx}
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: isProgressiveMode ? 0 : idx * 0.05 }}
className={cn(
'relative flex items-start gap-3 group',
onLocationClick && 'cursor-pointer',
)}
onClick={() => onLocationClick?.(idx)}
>
{/* Numbered marker */}
<div
className={cn(
'relative z-10 w-8 h-8 rounded-full flex items-center justify-center text-bg-primary text-xs font-semibold transition-all',
isCurrent
? 'bg-white shadow-lg ring-2 ring-white/50 scale-110'
: 'bg-white shadow-md',
isPast && !isCurrent && 'opacity-60',
)}
>
{idx + 1}
</div>
{/* Content */}
<div
className={cn(
'flex-1 py-1 transition-opacity',
isPast && !isCurrent && 'opacity-60',
isCurrent && 'opacity-100',
)}
onClick={(e) => {
if (loc.conversation_id && onConversationClick) {
e.stopPropagation();
onConversationClick(loc.conversation_id);
}
}}
>
{/* Time */}
<p
className={cn(
'text-xs font-medium',
isCurrent ? 'text-white' : 'text-white/70',
)}
>
{formatJourneyTime(loc.time)}
</p>
{/* Title */}
<div className="flex items-center gap-1.5 mt-0.5">
<span className="text-sm">{display.emoji}</span>
<p
className={cn(
'text-sm',
isCurrent
? 'text-text-primary font-medium'
: 'text-text-secondary',
loc.conversation_id &&
onConversationClick &&
'group-hover:text-white transition-colors',
)}
>
{display.title}
</p>
</div>
</div>
</motion.div>
);
})}
</div>
</div>
)}
</div>
</div>
);
}
export function RecapDetailPanel({
recapId,
recap: initialRecap,
onBack,
onConversationClick,
}: RecapDetailPanelProps) {
const router = useRouter();
const [recap, setRecap] = useState<DailySummary | null>(initialRecap || null);
const [loading, setLoading] = useState(!initialRecap);
const [previewConversationIds, setPreviewConversationIds] = useState<string[]>([]);
const [isPanelOpen, setIsPanelOpen] = useState(false);
const [activeTab, setActiveTab] = useState<RecapTab>('recap');
// Journey view playback state (lifted for sync between map and timeline)
const [journeyIndex, setJourneyIndex] = useState(-1);
const [journeyPlaying, setJourneyPlaying] = useState(false);
// Fetch full recap details if needed
useEffect(() => {
if (initialRecap) {
setRecap(initialRecap);
setLoading(false);
return;
}
const fetchRecap = async () => {
setLoading(true);
try {
const data = await getDailySummary(recapId);
setRecap(data);
} catch (err) {
console.error('Failed to load recap:', err);
} finally {
setLoading(false);
}
};
fetchRecap();
}, [recapId, initialRecap]);
// Extract all unique conversation IDs from the entire recap for prefetching
const allConversationIds = useMemo(() => {
if (!recap) return [];
const ids = new Set<string>();
// From locations
recap.locations?.forEach((loc) => {
if (loc.conversation_id) ids.add(loc.conversation_id);
});
// From highlights
recap.highlights?.forEach((h) => {
h.conversation_ids?.forEach((id) => ids.add(id));
});
// From action items
recap.action_items?.forEach((item) => {
if (item.source_conversation_id) ids.add(item.source_conversation_id);
});
// From questions, decisions, knowledge nuggets
recap.unresolved_questions?.forEach((q) => {
if (q.conversation_id) ids.add(q.conversation_id);
});
recap.decisions_made?.forEach((d) => {
if (d.conversation_id) ids.add(d.conversation_id);
});
recap.knowledge_nuggets?.forEach((k) => {
if (k.conversation_id) ids.add(k.conversation_id);
});
return Array.from(ids);
}, [recap]);
// Prefetch all conversations in parallel when recap loads
// This warms the API cache so child components get instant data
useEffect(() => {
if (allConversationIds.length === 0) return;
// Fire all requests in parallel instead of sequentially
// The API-level cache will deduplicate and cache results
Promise.all(allConversationIds.map((id) => getConversation(id).catch(() => {})));
}, [allConversationIds]);
// Handle click on source conversation - opens preview panel
const handleConversationClick = (conversationIds: string | string[]) => {
const ids = Array.isArray(conversationIds) ? conversationIds : [conversationIds];
setPreviewConversationIds(ids);
setIsPanelOpen(true);
};
// Handle opening full conversation view
const handleOpenFullConversation = (conversationId: string) => {
setIsPanelOpen(false);
if (onConversationClick) {
onConversationClick(conversationId);
} else {
router.push(`/conversations?id=${conversationId}`);
}
};
// Loading state
if (loading) {
return (
<div className="h-full flex flex-col bg-bg-secondary">
<div className="flex-1 flex items-center justify-center">
<Loader2 className="w-8 h-8 text-white animate-spin" />
</div>
</div>
);
}
// No recap found
if (!recap) {
return (
<div className="h-full flex flex-col bg-bg-secondary">
<div className="flex-1 flex items-center justify-center">
<p className="text-text-tertiary">Recap not found</p>
</div>
</div>
);
}
const hasHighlights = recap.highlights && recap.highlights.length > 0;
const hasTasks = recap.action_items && recap.action_items.length > 0;
const hasInsights =
(recap.unresolved_questions && recap.unresolved_questions.length > 0) ||
(recap.decisions_made && recap.decisions_made.length > 0) ||
(recap.knowledge_nuggets && recap.knowledge_nuggets.length > 0);
const hasLocations = recap.locations && recap.locations.length > 0;
return (
<div className="h-full flex bg-bg-secondary overflow-hidden">
{/* Main content area */}
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
{/* Header - always visible */}
<div className="flex-shrink-0 bg-bg-secondary border-b border-bg-tertiary z-10">
<div className="p-6">
<div className="flex items-start justify-between">
<div className="flex items-start gap-4">
{/* Day emoji */}
<div className="flex-shrink-0 w-14 h-14 rounded-2xl bg-gradient-to-br from-white/20 to-white/5 flex items-center justify-center text-3xl">
{recap.day_emoji || '📅'}
</div>
<div>
{/* Headline */}
<h2 className="text-xl font-semibold text-text-primary mb-1">
{recap.headline || 'Daily Recap'}
</h2>
{/* Date */}
<p className="text-sm text-text-tertiary">
{formatRecapDate(recap.date)}
</p>
</div>
</div>
</div>
{/* Quick stats row */}
<div className="flex items-center gap-4 mt-4">
<div className="flex items-center gap-1.5 text-text-secondary">
<MessageSquare className="w-4 h-4" />
<span className="text-sm font-medium">
{recap.stats.total_conversations}
</span>
<span className="text-xs text-text-tertiary">conversations</span>
</div>
{recap.stats.total_duration_minutes > 0 && (
<div className="flex items-center gap-1.5 text-text-secondary">
<Clock className="w-4 h-4" />
<span className="text-sm font-medium">
{formatDuration(recap.stats.total_duration_minutes)}
</span>
<span className="text-xs text-text-tertiary">recorded</span>
</div>
)}
{recap.stats.action_items_count > 0 && (
<div className="flex items-center gap-1.5 text-text-secondary">
<CheckSquare className="w-4 h-4" />
<span className="text-sm font-medium">
{recap.stats.action_items_count}
</span>
<span className="text-xs text-text-tertiary">tasks</span>
</div>
)}
</div>
{/* Tab switcher - only show if locations exist */}
{hasLocations && (
<div className="flex items-center gap-1 mt-4 p-1 bg-bg-tertiary/50 rounded-lg w-fit">
<button
onClick={() => setActiveTab('recap')}
className={cn(
'px-4 py-1.5 text-sm font-medium rounded-md transition-all',
activeTab === 'recap'
? 'bg-bg-secondary text-text-primary shadow-sm'
: 'text-text-tertiary hover:text-text-secondary',
)}
>
Recap
</button>
<button
onClick={() => {
setActiveTab('journey');
setJourneyIndex(-1);
setJourneyPlaying(false);
}}
className={cn(
'px-4 py-1.5 text-sm font-medium rounded-md transition-all flex items-center gap-1.5',
activeTab === 'journey'
? 'bg-bg-secondary text-text-primary shadow-sm'
: 'text-text-tertiary hover:text-text-secondary',
)}
>
<MapPin className="w-3.5 h-3.5" />
Journey
</button>
</div>
)}
</div>
</div>
{/* Recap Tab Content - scrollable */}
{activeTab === 'recap' && (
<div className="flex-1 overflow-y-auto p-6 space-y-8">
{/* Combined Overview + Map section (when both exist) */}
{recap.overview && hasLocations && (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.2 }}
className="noise-overlay rounded-xl overflow-hidden"
>
<div className="grid grid-cols-2 min-h-[280px]">
{/* Left: Overview text */}
<div className="p-5 pt-4">
<p className="text-sm text-text-secondary leading-relaxed">
{recap.overview}
</p>
</div>
{/* Right: Map */}
<div className="relative overflow-hidden group">
<LocationsSection
locations={recap.locations}
onConversationClick={handleConversationClick}
height={280}
showBorder={false}
className="h-full"
/>
{/* Expand button - switches to Journey tab */}
<button
onClick={() => setActiveTab('journey')}
className="absolute top-3 right-3 p-2 rounded-lg bg-bg-tertiary/80 backdrop-blur-sm text-text-secondary hover:text-text-primary hover:bg-bg-tertiary transition-all opacity-0 group-hover:opacity-100"
title="View full journey"
>
<Maximize2 className="w-4 h-4" />
</button>
</div>
</div>
</motion.div>
)}
{/* Standalone Overview (only when no locations) */}
{recap.overview && !hasLocations && (
<Section title="Overview" icon={Calendar}>
<div
className={cn(
'noise-overlay p-4 rounded-xl',
'bg-gradient-to-b from-white/[0.03] to-white/[0.01]',
'border border-white/[0.04]',
)}
>
<p className="text-sm text-text-secondary leading-relaxed">
{recap.overview}
</p>
</div>
</Section>
)}
{/* Highlights */}
{hasHighlights && (
<Section title="Highlights" icon={Sparkles}>
<HighlightsSection
highlights={recap.highlights}
onConversationClick={handleConversationClick}
/>
</Section>
)}
{/* Insights */}
{hasInsights && (
<Section title="Insights" icon={Lightbulb}>
<InsightsSection
questions={recap.unresolved_questions || []}
decisions={recap.decisions_made || []}
learnings={recap.knowledge_nuggets || []}
onConversationClick={handleConversationClick}
/>
</Section>
)}
{/* Tasks */}
{hasTasks && (
<Section title="Tasks" icon={CheckSquare}>
<TasksSection
tasks={recap.action_items}
onConversationClick={handleConversationClick}
/>
</Section>
)}
{/* Standalone Locations (only when no overview) */}
{hasLocations && !recap.overview && (
<Section title="Locations" icon={MapPin}>
<LocationsSection
locations={recap.locations}
onConversationClick={handleConversationClick}
/>
</Section>
)}
</div>
)}
{/* Journey Tab Content */}
{activeTab === 'journey' && hasLocations && (
<div className="flex-1 flex min-h-0 overflow-hidden">
{/* Map area - fixed, no scroll */}
<div className="flex-1 min-w-0 relative h-full">
<LocationMap
locations={recap.locations}
height="100%"
onConversationClick={(id) => handleConversationClick(id)}
showPlayback={true}
controlledIndex={journeyIndex}
onIndexChange={setJourneyIndex}
controlledPlaying={journeyPlaying}
onPlayingChange={setJourneyPlaying}
/>
</div>
{/* Journey Timeline Sidebar - scrollable */}
<div className="w-80 border-l border-white/[0.04] bg-bg-tertiary/30 flex flex-col h-full overflow-hidden">
<JourneyTimeline
locations={recap.locations}
onConversationClick={handleConversationClick}
currentIndex={journeyIndex}
onLocationClick={(idx) => {
setJourneyIndex(idx);
setJourneyPlaying(false);
}}
/>
</div>
</div>
)}
</div>
{/* Conversation Preview Panel */}
<ConversationPreviewPanel
conversationIds={previewConversationIds}
isOpen={isPanelOpen}
onClose={() => setIsPanelOpen(false)}
onOpenFull={handleOpenFullConversation}
/>
</div>
);
}
// Section wrapper component
interface SectionProps {
title: string;
icon: React.ComponentType<{ className?: string }>;
children: React.ReactNode;
}
function Section({ title, icon: Icon, children }: SectionProps) {
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.2 }}
>
{/* Section header */}
<div className="flex items-center gap-2 mb-3">
<Icon className="w-5 h-5 text-white" />
<h3 className="text-base font-semibold text-text-primary">{title}</h3>
</div>
{/* Section content */}
{children}
</motion.div>
);
}
// Skeleton for loading state
export function RecapDetailPanelSkeleton() {
return (
<div className="h-full flex flex-col bg-bg-secondary">
<div className="p-6 border-b border-bg-tertiary">
<div className="flex items-start gap-4">
<div className="w-14 h-14 rounded-2xl bg-bg-tertiary animate-pulse" />
<div className="flex-1 space-y-2">
<div className="h-6 w-64 bg-bg-tertiary rounded animate-pulse" />
<div className="h-4 w-40 bg-bg-tertiary rounded animate-pulse" />
</div>
</div>
</div>
<div className="flex-1 p-6 space-y-6">
<div className="h-24 bg-bg-tertiary rounded-xl animate-pulse" />
<div className="h-32 bg-bg-tertiary rounded-xl animate-pulse" />
<div className="h-48 bg-bg-tertiary rounded-xl animate-pulse" />
</div>
</div>
);
}