forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeConfirmationDialog.tsx
More file actions
194 lines (176 loc) · 6.42 KB
/
Copy pathMergeConfirmationDialog.tsx
File metadata and controls
194 lines (176 loc) · 6.42 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
'use client';
import { motion, AnimatePresence } from 'framer-motion';
import { AlertTriangle, Merge, X, Loader2 } from 'lucide-react';
import { cn } from '@/lib/utils';
import type { Conversation } from '@/types/conversation';
interface MergeConfirmationDialogProps {
isOpen: boolean;
conversations: Conversation[];
onConfirm: () => void;
onCancel: () => void;
isLoading?: boolean;
}
/**
* Detect time gaps between conversations
* Returns a warning message if gaps > 1 hour are found
*/
function detectTimeGaps(conversations: Conversation[]): string | null {
if (conversations.length < 2) return null;
// Sort by started_at
const sorted = [...conversations].sort((a, b) => {
const aTime = new Date(a.started_at || a.created_at).getTime();
const bTime = new Date(b.started_at || b.created_at).getTime();
return aTime - bTime;
});
const oneHour = 60 * 60 * 1000; // 1 hour in ms
let maxGapHours = 0;
for (let i = 1; i < sorted.length; i++) {
const prevEnd = sorted[i - 1].finished_at
? new Date(sorted[i - 1].finished_at!).getTime()
: new Date(sorted[i - 1].started_at || sorted[i - 1].created_at).getTime();
const currStart = new Date(sorted[i].started_at || sorted[i].created_at).getTime();
const gap = currStart - prevEnd;
if (gap > oneHour) {
const gapHours = Math.round(gap / oneHour);
maxGapHours = Math.max(maxGapHours, gapHours);
}
}
if (maxGapHours > 0) {
return `These conversations have gaps of up to ${maxGapHours} hour${maxGapHours > 1 ? 's' : ''} between them.`;
}
return null;
}
export function MergeConfirmationDialog({
isOpen,
conversations,
onConfirm,
onCancel,
isLoading = false,
}: MergeConfirmationDialogProps) {
const timeGapWarning = detectTimeGaps(conversations);
return (
<AnimatePresence>
{isOpen && (
<>
{/* Backdrop */}
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={onCancel}
className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm"
/>
{/* Dialog */}
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 20 }}
transition={{ type: 'spring', damping: 25, stiffness: 300 }}
className={cn(
'fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-50',
'w-full max-w-md p-6 rounded-2xl',
'bg-bg-secondary border border-bg-tertiary',
'shadow-[0_16px_64px_rgba(0,0,0,0.5)]'
)}
>
{/* Close button */}
<button
onClick={onCancel}
disabled={isLoading}
className={cn(
'absolute top-4 right-4 p-2 rounded-lg',
'text-text-quaternary hover:text-text-primary',
'hover:bg-bg-tertiary transition-colors',
'disabled:opacity-50 disabled:cursor-not-allowed'
)}
>
<X className="w-4 h-4" />
</button>
{/* Icon */}
<div className={cn(
'w-12 h-12 rounded-xl mb-4',
'bg-purple-primary/20 flex items-center justify-center'
)}>
<Merge className="w-6 h-6 text-purple-primary" />
</div>
{/* Title */}
<h2 className="text-lg font-semibold text-text-primary mb-2">
Merge {conversations.length} conversations?
</h2>
{/* Description */}
<p className="text-sm text-text-secondary mb-4">
The selected conversations will be combined into a single conversation.
This action is processed in the background.
</p>
{/* Time gap warning */}
{timeGapWarning && (
<div className={cn(
'flex items-start gap-3 p-3 rounded-xl mb-4',
'bg-warning/10 border border-warning/20'
)}>
<AlertTriangle className="w-5 h-5 text-warning flex-shrink-0 mt-0.5" />
<p className="text-sm text-warning">
{timeGapWarning}
</p>
</div>
)}
{/* Conversation list preview */}
<div className="max-h-40 overflow-y-auto mb-6 space-y-2">
{conversations.map((conv) => (
<div
key={conv.id}
className={cn(
'flex items-center gap-2 px-3 py-2 rounded-lg',
'bg-bg-tertiary'
)}
>
<span className="text-lg">
{conv.structured.emoji || '💬'}
</span>
<span className="text-sm text-text-primary truncate flex-1">
{conv.structured.title || 'Untitled'}
</span>
</div>
))}
</div>
{/* Actions */}
<div className="flex gap-3">
<button
onClick={onCancel}
disabled={isLoading}
className={cn(
'flex-1 px-4 py-2.5 rounded-xl',
'text-sm font-medium text-text-secondary',
'bg-bg-tertiary hover:bg-bg-quaternary',
'transition-colors duration-150',
'disabled:opacity-50 disabled:cursor-not-allowed'
)}
>
Cancel
</button>
<button
onClick={onConfirm}
disabled={isLoading}
className={cn(
'flex-1 flex items-center justify-center gap-2',
'px-4 py-2.5 rounded-xl',
'text-sm font-medium text-white',
'bg-purple-primary hover:bg-purple-primary/90',
'transition-colors duration-150',
'disabled:opacity-50 disabled:cursor-not-allowed'
)}
>
{isLoading ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Merge className="w-4 h-4" />
)}
<span>{isLoading ? 'Merging...' : 'Merge'}</span>
</button>
</div>
</motion.div>
</>
)}
</AnimatePresence>
);
}