Skip to content

Commit 7045c1c

Browse files
committed
webui: add "delete all conversations" button to import/export tab
- Add 'Delete all conversations' functionality with confirmation dialog - Add Trash icon and destructive styling for clear visual indication - Redirects to "?new_chat=true#/" by using conversationsStore.deleteConversation()
1 parent 96fe9ba commit 7045c1c

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

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

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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';
55
import { createMessageCountMap } from '$lib/utils';
66
import { conversationsStore, conversations } from '$lib/stores/conversations.svelte';
7+
import { toast } from 'svelte-sonner';
8+
import DialogConfirmation from '$lib/components/app/dialogs/DialogConfirmation.svelte';
79
810
let exportedConversations = $state<DatabaseConversation[]>([]);
911
let importedConversations = $state<DatabaseConversation[]>([]);
@@ -18,11 +20,14 @@
1820
[]
1921
);
2022
23+
// Delete functionality state
24+
let showDeleteDialog = $state(false);
25+
2126
async function handleExportClick() {
2227
try {
2328
const allConversations = conversations();
2429
if (allConversations.length === 0) {
25-
alert('No conversations to export');
30+
toast.info('No conversations to export');
2631
return;
2732
}
2833
@@ -145,6 +150,43 @@
145150
alert('Failed to import conversations. Please check the file format.');
146151
}
147152
}
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+
}
148190
</script>
149191

150192
<div class="space-y-6">
@@ -229,6 +271,25 @@
229271
</div>
230272
{/if}
231273
</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>
232293
</div>
233294
</div>
234295

@@ -249,3 +310,15 @@
249310
onCancel={() => (showImportDialog = false)}
250311
onConfirm={handleImportConfirm}
251312
/>
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

Comments
 (0)