forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderDialog.tsx
More file actions
366 lines (340 loc) · 14 KB
/
Copy pathFolderDialog.tsx
File metadata and controls
366 lines (340 loc) · 14 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
'use client';
import { useState, useEffect } from 'react';
import * as Dialog from '@radix-ui/react-dialog';
import { X, Loader2, FolderPlus, Pencil } from 'lucide-react';
import { cn } from '@/lib/utils';
import { FOLDER_EMOJIS, FOLDER_COLORS } from '@/types/folder';
import type { Folder, CreateFolderRequest, UpdateFolderRequest } from '@/types/folder';
interface FolderDialogProps {
isOpen: boolean;
folder?: Folder | null; // If provided, we're editing; otherwise creating
onClose: () => void;
onSubmit: (data: CreateFolderRequest | UpdateFolderRequest) => Promise<void>;
isLoading?: boolean;
}
export function FolderDialog({
isOpen,
folder,
onClose,
onSubmit,
isLoading = false,
}: FolderDialogProps) {
const isEditing = !!folder;
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [emoji, setEmoji] = useState<string>(FOLDER_EMOJIS[0]);
const [color, setColor] = useState<string>(FOLDER_COLORS[0].value);
// Reset form when dialog opens/closes or folder changes
useEffect(() => {
if (isOpen) {
if (folder) {
setName(folder.name);
setDescription(folder.description || '');
setEmoji(folder.emoji || FOLDER_EMOJIS[0]);
setColor(folder.color || FOLDER_COLORS[0].value);
} else {
setName('');
setDescription('');
setEmoji(FOLDER_EMOJIS[0]);
setColor(FOLDER_COLORS[0].value);
}
}
}, [isOpen, folder]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name.trim()) return;
await onSubmit({
name: name.trim(),
description: description.trim() || undefined,
icon: emoji, // Backend expects 'icon' field with emoji character
color,
});
};
const isValid = name.trim().length > 0;
return (
<Dialog.Root open={isOpen} onOpenChange={(open) => !open && onClose()}>
<Dialog.Portal>
{/* Backdrop */}
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" />
{/* Dialog Container - Centered with flexbox */}
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 text-center">
<Dialog.Content
className={cn(
'w-full max-w-md p-6 rounded-2xl text-left align-middle',
'bg-bg-secondary border border-bg-tertiary shadow-[0_16px_64px_rgba(0,0,0,0.5)]',
'max-h-[85vh] overflow-y-auto',
'duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]',
'outline-none focus:outline-none', // Remove default browser focus ring
)}
>
<Dialog.Title className="sr-only">
{isEditing ? 'Edit Folder' : 'Create Folder'}
</Dialog.Title>
{/* Close button */}
<button
onClick={onClose}
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',
'flex items-center justify-center',
)}
style={{ backgroundColor: `${color}20` }}
>
{isEditing ? (
<Pencil className="w-6 h-6" style={{ color }} />
) : (
<FolderPlus className="w-6 h-6" style={{ color }} />
)}
</div>
{/* Visible Title */}
<h2 className="text-lg font-semibold text-text-primary mb-4">
{isEditing ? 'Edit Folder' : 'Create Folder'}
</h2>
<form onSubmit={handleSubmit}>
{/* Folder name input */}
<div className="mb-4">
<label className="block text-sm font-medium text-text-secondary mb-2">
Folder name
</label>
<div className="flex items-center gap-2">
<span className="text-2xl">{emoji}</span>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter folder name..."
disabled={isLoading}
maxLength={100}
className={cn(
'flex-1 px-3 py-2 rounded-lg',
'bg-bg-tertiary border border-bg-quaternary',
'text-text-primary placeholder:text-text-quaternary',
'focus:outline-none focus:ring-2 focus:ring-white/25',
'disabled:opacity-50',
)}
autoFocus
/>
</div>
</div>
{/* Description input */}
<div className="mb-4">
<label className="block text-sm font-medium text-text-secondary mb-2">
Description{' '}
<span className="text-text-quaternary font-normal">(optional)</span>
</label>
<textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="E.g., Work meetings and project discussions"
disabled={isLoading}
maxLength={500}
rows={2}
className={cn(
'w-full px-3 py-2 rounded-lg resize-none',
'bg-bg-tertiary border border-bg-quaternary',
'text-text-primary placeholder:text-text-quaternary',
'text-sm',
'focus:outline-none focus:ring-2 focus:ring-white/25',
'disabled:opacity-50',
)}
/>
<p className="mt-1 text-xs text-text-quaternary">
Helps AI auto-categorize conversations into this folder
</p>
</div>
{/* Emoji picker */}
<div className="mb-4">
<label className="block text-sm font-medium text-text-secondary mb-2">
Icon
</label>
<div className="flex flex-wrap gap-2">
{FOLDER_EMOJIS.map((e) => (
<button
key={e}
type="button"
onClick={() => setEmoji(e)}
disabled={isLoading}
className={cn(
'w-10 h-10 rounded-lg text-xl',
'flex items-center justify-center',
'transition-all duration-150',
emoji === e
? 'bg-white/[0.14] ring-2 ring-white/25'
: 'bg-bg-tertiary hover:bg-bg-quaternary',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
>
{e}
</button>
))}
</div>
</div>
{/* Color picker */}
<div className="mb-6">
<label className="block text-sm font-medium text-text-secondary mb-2">
Color
</label>
<div className="flex flex-wrap gap-2">
{FOLDER_COLORS.map((c) => (
<button
key={c.id}
type="button"
onClick={() => setColor(c.value)}
disabled={isLoading}
className={cn(
'w-8 h-8 rounded-full',
'transition-all duration-150',
color === c.value
? 'ring-2 ring-offset-2 ring-offset-bg-secondary'
: 'hover:scale-110',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
style={
{
backgroundColor: c.value,
'--tw-ring-color': c.value,
} as React.CSSProperties
}
title={c.label}
/>
))}
</div>
</div>
{/* Actions */}
<div className="flex gap-3">
<button
type="button"
onClick={onClose}
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
type="submit"
disabled={!isValid || 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',
'transition-colors duration-150',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
style={{ backgroundColor: isValid ? color : undefined }}
>
{isLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : null}
<span>{isEditing ? 'Save Changes' : 'Create Folder'}</span>
</button>
</div>
</form>
</Dialog.Content>
</div>
</Dialog.Portal>
</Dialog.Root>
);
}
// Confirm delete folder dialog
interface DeleteFolderDialogProps {
isOpen: boolean;
folder: Folder | null;
onClose: () => void;
onConfirm: () => Promise<void>;
isLoading?: boolean;
}
export function DeleteFolderDialog({
isOpen,
folder,
onClose,
onConfirm,
isLoading = false,
}: DeleteFolderDialogProps) {
if (!folder) return null;
return (
<Dialog.Root open={isOpen} onOpenChange={(open) => !open && onClose()}>
<Dialog.Portal>
{/* Backdrop */}
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" />
{/* Dialog Container */}
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 text-center">
<Dialog.Content
className={cn(
'w-full max-w-sm p-6 rounded-2xl text-left align-middle',
'bg-bg-secondary border border-bg-tertiary shadow-[0_16px_64px_rgba(0,0,0,0.5)]',
'max-h-[85vh] overflow-y-auto',
'duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]',
'outline-none focus:outline-none',
)}
>
<Dialog.Title className="sr-only">Delete Folder Confirmation</Dialog.Title>
{/* Icon */}
<div
className={cn(
'w-12 h-12 rounded-xl mb-4',
'bg-error/20 flex items-center justify-center',
)}
>
<span className="text-2xl">{folder.emoji || '📁'}</span>
</div>
{/* Title */}
<h2 className="text-lg font-semibold text-text-primary mb-2">
Delete "{folder.name}"?
</h2>
{/* Description */}
<p className="text-sm text-text-secondary mb-6">
Conversations in this folder will be moved back to "All". This
action cannot be undone.
</p>
{/* Actions */}
<div className="flex gap-3">
<button
onClick={onClose}
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-error hover:bg-error/90',
'transition-colors duration-150',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
>
{isLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : null}
<span>Delete Folder</span>
</button>
</div>
</Dialog.Content>
</div>
</Dialog.Portal>
</Dialog.Root>
);
}