Skip to content

Commit 409be35

Browse files
authored
Merge pull request #1 from allozaur/allozaur/import-export-ux-improvements
UX Improvements for Export/Import feature
2 parents 9a28dc1 + 9844fed commit 409be35

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

tools/server/webui/src/lib/components/app/chat/ChatSidebar/ChatSidebarActions.svelte

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,32 @@
7979
<KeyboardShortcutInfo keys={['cmd', 'k']} />
8080
</Button>
8181

82-
<!-- Export All Conversations -->
8382
<Button
8483
class="w-full justify-start text-sm"
8584
onclick={() => {
86-
exportAllConversations();
85+
importConversations().catch((err) => {
86+
console.error('Import failed:', err);
87+
// Optional: show toast or dialog
88+
});
8789
}}
8890
variant="ghost"
8991
>
9092
<div class="flex items-center gap-2">
91-
<Download class="h-4 w-4" />
92-
Export all
93+
<Upload class="h-4 w-4" />
94+
Import conversations
9395
</div>
9496
</Button>
9597

96-
<!-- Import Conversations -->
9798
<Button
9899
class="w-full justify-start text-sm"
99100
onclick={() => {
100-
importConversations().catch(err => {
101-
console.error('Import failed:', err);
102-
// Optional: show toast or dialog
103-
});
101+
exportAllConversations();
104102
}}
105103
variant="ghost"
106104
>
107-
108105
<div class="flex items-center gap-2">
109-
<Upload class="h-4 w-4" />
110-
Import all
106+
<Download class="h-4 w-4" />
107+
Export all conversations
111108
</div>
112109
</Button>
113110
{/if}

tools/server/webui/src/lib/components/app/chat/ChatSidebar/ChatSidebarConversationItem.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
},
105105
{
106106
icon: Download,
107-
label: 'Download',
107+
label: 'Export',
108108
onclick: (e) => {
109109
e.stopPropagation();
110110
downloadConversation(conversation.id);

tools/server/webui/src/lib/stores/chat.svelte.ts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -958,27 +958,27 @@ class ChatStore {
958958
* @param convId - The conversation ID to download
959959
*/
960960
async downloadConversation(convId: string): Promise<void> {
961-
if (!this.activeConversation || this.activeConversation.id !== convId) {
962-
// Load the conversation if not currently active
963-
const conversation = await DatabaseStore.getConversation(convId);
964-
if (!conversation) return;
965-
966-
const messages = await DatabaseStore.getConversationMessages(convId);
967-
const conversationData = {
968-
conv: conversation,
969-
messages
970-
};
961+
if (!this.activeConversation || this.activeConversation.id !== convId) {
962+
// Load the conversation if not currently active
963+
const conversation = await DatabaseStore.getConversation(convId);
964+
if (!conversation) return;
971965

972-
this.triggerDownload(conversationData);
973-
} else {
974-
// Use current active conversation data
975-
const conversationData: ExportedConversations = {
976-
conv: this.activeConversation!,
977-
messages: this.activeMessages
978-
};
966+
const messages = await DatabaseStore.getConversationMessages(convId);
967+
const conversationData = {
968+
conv: conversation,
969+
messages
970+
};
979971

980-
this.triggerDownload(conversationData);
981-
}
972+
this.triggerDownload(conversationData);
973+
} else {
974+
// Use current active conversation data
975+
const conversationData: ExportedConversations = {
976+
conv: this.activeConversation!,
977+
messages: this.activeMessages
978+
};
979+
980+
this.triggerDownload(conversationData);
981+
}
982982
}
983983

984984
/**
@@ -987,20 +987,24 @@ class ChatStore {
987987
* @param filename - Optional filename
988988
*/
989989
private triggerDownload(data: ExportedConversations, filename?: string): void {
990-
const conversation = 'conv' in data ? data.conv : (Array.isArray(data) ? data[0]?.conv : undefined);
990+
const conversation =
991+
'conv' in data ? data.conv : Array.isArray(data) ? data[0]?.conv : undefined;
991992
if (!conversation) {
992993
console.error('Invalid data: missing conversation');
993994
return;
994995
}
995996
const conversationName = conversation.name ? conversation.name.trim() : '';
996997
const convId = conversation.id || 'unknown';
997-
const truncatedSuffix = conversationName.toLowerCase()
998-
.replace(/[^a-z0-9]/gi, '_').replace(/_+/g, '_').substring(0, 20);
998+
const truncatedSuffix = conversationName
999+
.toLowerCase()
1000+
.replace(/[^a-z0-9]/gi, '_')
1001+
.replace(/_+/g, '_')
1002+
.substring(0, 20);
9991003
const downloadFilename = filename || `conversation_${convId}_${truncatedSuffix}.json`;
10001004

10011005
const conversationJson = JSON.stringify(data, null, 2);
10021006
const blob = new Blob([conversationJson], {
1003-
type: 'application/json',
1007+
type: 'application/json'
10041008
});
10051009
const url = URL.createObjectURL(blob);
10061010
const a = document.createElement('a');
@@ -1073,11 +1077,18 @@ class ChatStore {
10731077

10741078
if (Array.isArray(parsedData)) {
10751079
importedData = parsedData;
1076-
} else if (parsedData && typeof parsedData === 'object' && 'conv' in parsedData && 'messages' in parsedData) {
1080+
} else if (
1081+
parsedData &&
1082+
typeof parsedData === 'object' &&
1083+
'conv' in parsedData &&
1084+
'messages' in parsedData
1085+
) {
10771086
// Single conversation object
10781087
importedData = [parsedData];
10791088
} else {
1080-
throw new Error('Invalid file format: expected array of conversations or single conversation object');
1089+
throw new Error(
1090+
'Invalid file format: expected array of conversations or single conversation object'
1091+
);
10811092
}
10821093

10831094
const result = await DatabaseStore.importConversations(importedData);

tools/server/webui/src/lib/stores/database.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,4 @@ export class DatabaseStore {
381381
return { imported: importedCount, skipped: skippedCount };
382382
});
383383
}
384-
385384
}

0 commit comments

Comments
 (0)