Skip to content

Commit 43553bb

Browse files
committed
webui: add "delete all conversations" button to import/export tab
- Add 'Delete all conversations' functionality with confirmation dialog - Implement safe deletion with proper error handling and user feedback - Add Trash icon and destructive styling for clear visual indication - Include success summary showing count of deleted conversations
1 parent 3f3a4fb commit 43553bb

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettingsImportExportTab.svelte

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts">
2-
import { Download, Upload } from '@lucide/svelte';
2+
import { Download, Upload, Trash2 } from '@lucide/svelte';
33
import { Button } from '$lib/components/ui/button';
44
import { DialogConversationSelection } from '$lib/components/app';
5+
import DialogConfirmation from '$lib/components/app/dialogs/DialogConfirmation.svelte';
56
import { DatabaseStore } from '$lib/stores/database';
67
import type { ExportedConversations } from '$lib/types/database';
78
import { createMessageCountMap } from '$lib/utils/conversation-utils';
@@ -20,6 +21,11 @@
2021
[]
2122
);
2223
24+
// Delete functionality state
25+
let showDeleteDialog = $state(false);
26+
let deletedCount = $state(0);
27+
let showDeleteSummary = $state(false);
28+
2329
async function handleExportClick() {
2430
try {
2531
const allConversations = await DatabaseStore.getAllConversations();
@@ -149,6 +155,50 @@
149155
alert('Failed to import conversations. Please check the file format.');
150156
}
151157
}
158+
159+
async function handleDeleteAllClick() {
160+
try {
161+
const allConversations = await DatabaseStore.getAllConversations();
162+
if (allConversations.length === 0) {
163+
alert('No conversations to delete');
164+
return;
165+
}
166+
showDeleteDialog = true;
167+
} catch (err) {
168+
console.error('Failed to load conversations for deletion:', err);
169+
alert('Failed to load conversations');
170+
}
171+
}
172+
173+
async function handleDeleteAllConfirm() {
174+
try {
175+
const allConversations = await DatabaseStore.getAllConversations();
176+
let deleted = 0;
177+
178+
// Delete each conversation and its messages
179+
for (const conv of allConversations) {
180+
await DatabaseStore.deleteConversation(conv.id);
181+
deleted++;
182+
}
183+
184+
// Update chat store to reflect the changes
185+
await chatStore.loadConversations();
186+
chatStore.clearActiveConversation();
187+
188+
deletedCount = deleted;
189+
showDeleteSummary = true;
190+
showDeleteDialog = false;
191+
showExportSummary = false;
192+
showImportSummary = false;
193+
} catch (err) {
194+
console.error('Failed to delete conversations:', err);
195+
alert('Failed to delete conversations');
196+
}
197+
}
198+
199+
function handleDeleteAllCancel() {
200+
showDeleteDialog = false;
201+
}
152202
</script>
153203

154204
<div class="space-y-6">
@@ -233,6 +283,38 @@
233283
</div>
234284
{/if}
235285
</div>
286+
287+
<div class="grid border-t border-border/30 pt-4">
288+
<h4 class="mb-2 text-sm font-medium text-destructive">Delete All Conversations</h4>
289+
290+
<p class="mb-4 text-sm text-muted-foreground">
291+
Permanently delete all conversations and their messages. This action cannot be undone.
292+
Consider exporting your conversations first if you want to keep a backup.
293+
</p>
294+
295+
<Button
296+
class="text-destructive-foreground w-full justify-start justify-self-start bg-destructive hover:bg-destructive/80 md:w-auto"
297+
onclick={handleDeleteAllClick}
298+
variant="destructive"
299+
>
300+
<Trash2 class="mr-2 h-4 w-4" />
301+
302+
Delete all conversations
303+
</Button>
304+
305+
{#if showDeleteSummary && deletedCount > 0}
306+
<div
307+
class="mt-4 grid overflow-x-auto rounded-lg border border-destructive/50 bg-destructive/10 p-4"
308+
>
309+
<h5 class="mb-2 text-sm font-medium text-destructive">
310+
Deleted {deletedCount} conversation{deletedCount === 1 ? '' : 's'}
311+
</h5>
312+
<p class="text-sm text-muted-foreground">
313+
All conversations have been permanently removed from your device.
314+
</p>
315+
</div>
316+
{/if}
317+
</div>
236318
</div>
237319
</div>
238320

@@ -253,3 +335,15 @@
253335
onCancel={() => (showImportDialog = false)}
254336
onConfirm={handleImportConfirm}
255337
/>
338+
339+
<DialogConfirmation
340+
bind:open={showDeleteDialog}
341+
title="Delete all conversations"
342+
description="Are you sure you want to delete all conversations? This action cannot be undone and will permanently remove all your conversations and messages."
343+
confirmText="Delete All"
344+
cancelText="Cancel"
345+
variant="destructive"
346+
icon={Trash2}
347+
onConfirm={handleDeleteAllConfirm}
348+
onCancel={handleDeleteAllCancel}
349+
/>

0 commit comments

Comments
 (0)