Skip to content

Commit f5ac5dc

Browse files
committed
refactor: Cleanup
1 parent d4e07c6 commit f5ac5dc

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@
2828
let searchQuery = $state('');
2929
let selectedIds = $state.raw<SvelteSet<string>>(new SvelteSet(conversations.map((c) => c.id)));
3030
31-
// Filter conversations based on search query
3231
let filteredConversations = $derived(
3332
conversations.filter((conv) => {
3433
const name = conv.name || 'Untitled conversation';
3534
return name.toLowerCase().includes(searchQuery.toLowerCase());
3635
})
3736
);
3837
39-
// Check if all filtered conversations are selected
4038
let allSelected = $derived(
4139
filteredConversations.length > 0 &&
4240
filteredConversations.every((conv) => selectedIds.has(conv.id))
4341
);
4442
45-
// Check if some (but not all) filtered conversations are selected
4643
let someSelected = $derived(
4744
filteredConversations.some((conv) => selectedIds.has(conv.id)) && !allSelected
4845
);
@@ -59,13 +56,13 @@
5956
6057
function toggleAll() {
6158
if (allSelected) {
62-
// Deselect all filtered conversations
6359
const newSet = new SvelteSet(selectedIds);
60+
6461
filteredConversations.forEach((conv) => newSet.delete(conv.id));
6562
selectedIds = newSet;
6663
} else {
67-
// Select all filtered conversations
6864
const newSet = new SvelteSet(selectedIds);
65+
6966
filteredConversations.forEach((conv) => newSet.add(conv.id));
7067
selectedIds = newSet;
7168
}
@@ -77,37 +74,36 @@
7774
}
7875
7976
function handleCancel() {
80-
// Reset selection to all conversations
8177
selectedIds = new SvelteSet(conversations.map((c) => c.id));
8278
searchQuery = '';
79+
8380
onCancel();
8481
}
8582
86-
// Track previous open state to detect close
8783
let previousOpen = $state(false);
8884
89-
// Reset selection when dialog opens, call onCancel when it closes
9085
$effect(() => {
9186
if (open && !previousOpen) {
92-
// Dialog just opened
9387
selectedIds = new SvelteSet(conversations.map((c) => c.id));
9488
searchQuery = '';
9589
} else if (!open && previousOpen) {
96-
// Dialog just closed
9790
onCancel();
9891
}
92+
9993
previousOpen = open;
10094
});
10195
</script>
10296

10397
<Dialog.Root bind:open>
10498
<Dialog.Portal>
10599
<Dialog.Overlay class="z-[1000000]" />
100+
106101
<Dialog.Content class="z-[1000001] max-w-2xl">
107102
<Dialog.Header>
108103
<Dialog.Title>
109104
Select Conversations to {mode === 'export' ? 'Export' : 'Import'}
110105
</Dialog.Title>
106+
111107
<Dialog.Description>
112108
{#if mode === 'export'}
113109
Choose which conversations you want to export. Selected conversations will be downloaded
@@ -120,10 +116,11 @@
120116
</Dialog.Header>
121117

122118
<div class="space-y-4">
123-
<!-- Search Input -->
124119
<div class="relative">
125120
<Search class="absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
121+
126122
<Input bind:value={searchQuery} placeholder="Search conversations..." class="pr-9 pl-9" />
123+
127124
{#if searchQuery}
128125
<button
129126
class="absolute top-1/2 right-3 -translate-y-1/2 text-muted-foreground hover:text-foreground"
@@ -135,7 +132,6 @@
135132
{/if}
136133
</div>
137134

138-
<!-- Selection Summary -->
139135
<div class="flex items-center justify-between text-sm text-muted-foreground">
140136
<span>
141137
{selectedIds.size} of {conversations.length} selected
@@ -145,7 +141,6 @@
145141
</span>
146142
</div>
147143

148-
<!-- Conversations Table -->
149144
<div class="overflow-hidden rounded-md border">
150145
<ScrollArea class="h-[400px]">
151146
<table class="w-full">
@@ -158,7 +153,9 @@
158153
onCheckedChange={toggleAll}
159154
/>
160155
</th>
156+
161157
<th class="p-3 text-left text-sm font-medium">Conversation Name</th>
158+
162159
<th class="w-32 p-3 text-left text-sm font-medium">Messages</th>
163160
</tr>
164161
</thead>
@@ -185,6 +182,7 @@
185182
onCheckedChange={() => toggleConversation(conv.id)}
186183
/>
187184
</td>
185+
188186
<td class="p-3 text-sm">
189187
<div
190188
class="max-w-[17rem] truncate"
@@ -193,6 +191,7 @@
193191
{conv.name || 'Untitled conversation'}
194192
</div>
195193
</td>
194+
196195
<td class="p-3 text-sm text-muted-foreground">
197196
{messageCountMap.get(conv.id) ?? 0}
198197
</td>
@@ -207,6 +206,7 @@
207206

208207
<Dialog.Footer>
209208
<Button variant="outline" onclick={handleCancel}>Cancel</Button>
209+
210210
<Button onclick={handleConfirm} disabled={selectedIds.size === 0}>
211211
{mode === 'export' ? 'Export' : 'Import'} ({selectedIds.size})
212212
</Button>

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import ConversationSelectionDialog from './ConversationSelectionDialog.svelte';
55
import { DatabaseStore } from '$lib/stores/database';
66
import type { ExportedConversations } from '$lib/types/database';
7-
import { createMessageCountMap } from '$lib/utils/conversationUtils';
7+
import { createMessageCountMap } from '$lib/utils/conversation-utils';
88
import { chatStore } from '$lib/stores/chat.svelte';
99
1010
let exportedConversations = $state<DatabaseConversation[]>([]);
1111
let importedConversations = $state<DatabaseConversation[]>([]);
1212
let showExportSummary = $state(false);
1313
let showImportSummary = $state(false);
1414
15-
// Dialog state
1615
let showExportDialog = $state(false);
1716
let showImportDialog = $state(false);
1817
let availableConversations = $state<DatabaseConversation[]>([]);
@@ -23,22 +22,19 @@
2322
2423
async function handleExportClick() {
2524
try {
26-
// Load all conversations for selection
2725
const allConversations = await DatabaseStore.getAllConversations();
2826
if (allConversations.length === 0) {
2927
alert('No conversations to export');
3028
return;
3129
}
3230
33-
// Load messages for each conversation to get counts
3431
const conversationsWithMessages = await Promise.all(
3532
allConversations.map(async (conv) => {
3633
const messages = await DatabaseStore.getConversationMessages(conv.id);
3734
return { conv, messages };
3835
})
3936
);
4037
41-
// Create message count map
4238
messageCountMap = createMessageCountMap(conversationsWithMessages);
4339
availableConversations = allConversations;
4440
showExportDialog = true;
@@ -50,7 +46,6 @@
5046
5147
async function handleExportConfirm(selectedConversations: DatabaseConversation[]) {
5248
try {
53-
// Export selected conversations - use snapshot to get plain objects
5449
const allData: ExportedConversations = await Promise.all(
5550
selectedConversations.map(async (conv) => {
5651
const messages = await DatabaseStore.getConversationMessages(conv.id);
@@ -63,6 +58,7 @@
6358
});
6459
const url = URL.createObjectURL(blob);
6560
const a = document.createElement('a');
61+
6662
a.href = url;
6763
a.download = `conversations_${new Date().toISOString().split('T')[0]}.json`;
6864
document.body.appendChild(a);
@@ -82,8 +78,8 @@
8278
8379
async function handleImportClick() {
8480
try {
85-
// Open file picker
8681
const input = document.createElement('input');
82+
8783
input.type = 'file';
8884
input.accept = '.json';
8985
@@ -112,17 +108,15 @@
112108
);
113109
}
114110
115-
// Store full import data and extract conversations for selection dialog
116111
fullImportData = importedData;
117112
availableConversations = importedData.map(
118113
(item: { conv: DatabaseConversation; messages: DatabaseMessage[] }) => item.conv
119114
);
120-
121-
// Create message count map from imported data
122115
messageCountMap = createMessageCountMap(importedData);
123116
showImportDialog = true;
124117
} catch (err: unknown) {
125118
const message = err instanceof Error ? err.message : 'Unknown error';
119+
126120
console.error('Failed to parse file:', err);
127121
alert(`Failed to parse file: ${message}`);
128122
}
@@ -137,16 +131,13 @@
137131
138132
async function handleImportConfirm(selectedConversations: DatabaseConversation[]) {
139133
try {
140-
// Filter the original import data to only include selected conversations
141134
const selectedIds = new Set(selectedConversations.map((c) => c.id));
142135
const selectedData = $state
143136
.snapshot(fullImportData)
144137
.filter((item) => selectedIds.has(item.conv.id));
145138
146-
// Import selected conversations with their messages
147139
await DatabaseStore.importConversations(selectedData);
148140
149-
// Refresh the conversations list in the chat store
150141
await chatStore.loadConversations();
151142
152143
importedConversations = selectedConversations;
@@ -245,7 +236,6 @@
245236
</div>
246237
</div>
247238

248-
<!-- Export Dialog -->
249239
<ConversationSelectionDialog
250240
conversations={availableConversations}
251241
{messageCountMap}
@@ -255,7 +245,6 @@
255245
onConfirm={handleExportConfirm}
256246
/>
257247

258-
<!-- Import Dialog -->
259248
<ConversationSelectionDialog
260249
conversations={availableConversations}
261250
{messageCountMap}

0 commit comments

Comments
 (0)