|
1 | 1 | <script lang="ts"> |
2 | | - import { Download, Upload } from '@lucide/svelte'; |
| 2 | + import { Download, Upload, Trash2 } from '@lucide/svelte'; |
3 | 3 | import { Button } from '$lib/components/ui/button'; |
4 | 4 | import { DialogConversationSelection } from '$lib/components/app'; |
5 | 5 | import { createMessageCountMap } from '$lib/utils'; |
6 | 6 | import { conversationsStore, conversations } from '$lib/stores/conversations.svelte'; |
| 7 | + import { toast } from 'svelte-sonner'; |
| 8 | + import DialogConfirmation from '$lib/components/app/dialogs/DialogConfirmation.svelte'; |
7 | 9 |
|
8 | 10 | let exportedConversations = $state<DatabaseConversation[]>([]); |
9 | 11 | let importedConversations = $state<DatabaseConversation[]>([]); |
|
18 | 20 | [] |
19 | 21 | ); |
20 | 22 |
|
| 23 | + // Delete functionality state |
| 24 | + let showDeleteDialog = $state(false); |
| 25 | +
|
21 | 26 | async function handleExportClick() { |
22 | 27 | try { |
23 | 28 | const allConversations = conversations(); |
24 | 29 | if (allConversations.length === 0) { |
25 | | - alert('No conversations to export'); |
| 30 | + toast.info('No conversations to export'); |
26 | 31 | return; |
27 | 32 | } |
28 | 33 |
|
|
145 | 150 | alert('Failed to import conversations. Please check the file format.'); |
146 | 151 | } |
147 | 152 | } |
| 153 | +
|
| 154 | + async function handleDeleteAllClick() { |
| 155 | + try { |
| 156 | + const allConversations = conversations(); |
| 157 | +
|
| 158 | + if (allConversations.length === 0) { |
| 159 | + toast.info('No conversations to delete'); |
| 160 | + return; |
| 161 | + } |
| 162 | +
|
| 163 | + showDeleteDialog = true; |
| 164 | + } catch (err) { |
| 165 | + console.error('Failed to load conversations for deletion:', err); |
| 166 | + toast.error('Failed to load conversations'); |
| 167 | + } |
| 168 | + } |
| 169 | +
|
| 170 | + async function handleDeleteAllConfirm() { |
| 171 | + try { |
| 172 | + const allConversations = conversations(); |
| 173 | +
|
| 174 | + // Delete each conversation and its messages |
| 175 | + for (const conv of allConversations) { |
| 176 | + await conversationsStore.deleteConversation(conv.id); |
| 177 | + } |
| 178 | +
|
| 179 | + toast.success('All conversations deleted'); |
| 180 | + showDeleteDialog = false; |
| 181 | + } catch (err) { |
| 182 | + console.error('Failed to delete conversations:', err); |
| 183 | + toast.error('Failed to delete conversations'); |
| 184 | + } |
| 185 | + } |
| 186 | +
|
| 187 | + function handleDeleteAllCancel() { |
| 188 | + showDeleteDialog = false; |
| 189 | + } |
148 | 190 | </script> |
149 | 191 |
|
150 | 192 | <div class="space-y-6"> |
|
229 | 271 | </div> |
230 | 272 | {/if} |
231 | 273 | </div> |
| 274 | + |
| 275 | + <div class="grid border-t border-border/30 pt-4"> |
| 276 | + <h4 class="mb-2 text-sm font-medium text-destructive">Delete All Conversations</h4> |
| 277 | + |
| 278 | + <p class="mb-4 text-sm text-muted-foreground"> |
| 279 | + Permanently delete all conversations and their messages. This action cannot be undone. |
| 280 | + Consider exporting your conversations first if you want to keep a backup. |
| 281 | + </p> |
| 282 | + |
| 283 | + <Button |
| 284 | + class="text-destructive-foreground w-full justify-start justify-self-start bg-destructive hover:bg-destructive/80 md:w-auto" |
| 285 | + onclick={handleDeleteAllClick} |
| 286 | + variant="destructive" |
| 287 | + > |
| 288 | + <Trash2 class="mr-2 h-4 w-4" /> |
| 289 | + |
| 290 | + Delete all conversations |
| 291 | + </Button> |
| 292 | + </div> |
232 | 293 | </div> |
233 | 294 | </div> |
234 | 295 |
|
|
249 | 310 | onCancel={() => (showImportDialog = false)} |
250 | 311 | onConfirm={handleImportConfirm} |
251 | 312 | /> |
| 313 | + |
| 314 | +<DialogConfirmation |
| 315 | + bind:open={showDeleteDialog} |
| 316 | + title="Delete all conversations" |
| 317 | + description="Are you sure you want to delete all conversations? This action cannot be undone and will permanently remove all your conversations and messages." |
| 318 | + confirmText="Delete All" |
| 319 | + cancelText="Cancel" |
| 320 | + variant="destructive" |
| 321 | + icon={Trash2} |
| 322 | + onConfirm={handleDeleteAllConfirm} |
| 323 | + onCancel={handleDeleteAllCancel} |
| 324 | +/> |
0 commit comments