From 5b6ba80b50a600cbe8c243fb42a11785ec6b94f6 Mon Sep 17 00:00:00 2001 From: Siddharth Venkumahanti <94043668+sidbetatester@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:50:20 -0800 Subject: [PATCH] refactor: simplify chat import formats - Remove multi-format support from DataTab - Keep only standard Bolt export formats - Simplify ImportButtons to handle standard format only --- .../chatExportAndImport/ImportButtons.tsx | 22 ----- app/components/settings/data/DataTab.tsx | 96 ++++++------------- 2 files changed, 28 insertions(+), 90 deletions(-) diff --git a/app/components/chat/chatExportAndImport/ImportButtons.tsx b/app/components/chat/chatExportAndImport/ImportButtons.tsx index 5fcea1e16..c6b25579a 100644 --- a/app/components/chat/chatExportAndImport/ImportButtons.tsx +++ b/app/components/chat/chatExportAndImport/ImportButtons.tsx @@ -5,10 +5,6 @@ import { ImportFolderButton } from '~/components/chat/ImportFolderButton'; type ChatData = { messages?: Message[]; // Standard Bolt format description?: string; // Optional description - history?: Array<{ messages: Message[]; description?: string }>; // Backup format - boltHistory?: { - chats: Record; // Chrome extension format - }; }; export function ImportButtons(importChat: ((description: string, messages: Message[]) => Promise) | undefined) { @@ -38,24 +34,6 @@ export function ImportButtons(importChat: ((description: string, messages: Messa return; } - // Backup format - if (data.history?.[0]?.messages) { - const chat = data.history[0]; - await importChat(chat.description || 'Imported Chat', chat.messages); - toast.success('Chat imported successfully'); - return; - } - - // Chrome format - if (data.boltHistory?.chats) { - const chat = Object.values(data.boltHistory.chats)[0]; - if (chat?.messages) { - await importChat(chat.description || 'Imported Chat', chat.messages); - toast.success('Chat imported successfully'); - return; - } - } - toast.error('Invalid chat file format'); } catch (error: unknown) { if (error instanceof Error) { diff --git a/app/components/settings/data/DataTab.tsx b/app/components/settings/data/DataTab.tsx index 293a6cd36..518fdf770 100644 --- a/app/components/settings/data/DataTab.tsx +++ b/app/components/settings/data/DataTab.tsx @@ -232,85 +232,45 @@ export default function DataTab() { event.target.value = ''; }; - const handleImportChats = () => { - const input = document.createElement('input'); - input.type = 'file'; - input.accept = '.json'; - - const processChatData = (data: any): Array<{ - id: string; - messages: Message[]; - description: string; - urlId?: string; - }> => { - // Add logging to debug format detection - console.log('Processing data:', { - hasMessages: !!data.messages, - isMessagesArray: Array.isArray(data.messages), - hasBoltHistory: !!data.boltHistory, - hasHistory: !!data.history, - hasChats: !!data.chats, - keys: Object.keys(data) - }); - - // Handle Bolt standard format (single chat) - if (data.messages && Array.isArray(data.messages)) { - console.log('Importing single chat:', { - messages: data.messages.length, - description: data.description - }); - - // Generate both id and urlId for single chat - const chatId = crypto.randomUUID(); - return [{ - id: chatId, - messages: data.messages, - description: data.description || 'Imported Chat', - urlId: chatId // Add urlId for proper navigation - }]; - } - - // Handle Chrome extension format - if (data.boltHistory?.chats) { - return Object.values(data.boltHistory.chats).map((chat: any) => ({ - id: chat.id || crypto.randomUUID(), - messages: chat.messages, - description: chat.description || 'Imported Chat', - urlId: chat.urlId - })); - } - - // Handle history array format - if (data.history && Array.isArray(data.history)) { - return data.history.map((chat: any) => ({ - id: chat.id || crypto.randomUUID(), - messages: chat.messages, - description: chat.description || 'Imported Chat', - urlId: chat.urlId - })); - } + const processChatData = (data: any): Array<{ + id: string; + messages: Message[]; + description: string; + urlId?: string; + }> => { + // Handle Bolt standard format (single chat) + if (data.messages && Array.isArray(data.messages)) { + const chatId = crypto.randomUUID(); + return [{ + id: chatId, + messages: data.messages, + description: data.description || 'Imported Chat', + urlId: chatId + }]; + } // Handle Bolt export format (multiple chats) if (data.chats && Array.isArray(data.chats)) { - return data.chats.map((chat: { - id?: string; - messages: Message[]; - description?: string; - urlId?: string; - }) => ({ + return data.chats.map((chat: { id?: string; messages: Message[]; description?: string; urlId?: string; }) => ({ id: chat.id || crypto.randomUUID(), messages: chat.messages, description: chat.description || 'Imported Chat', - urlId: chat.urlId + urlId: chat.urlId, })); } - console.error('No matching format found for:', data); - throw new Error('Unsupported chat format'); - }; + console.error('No matching format found for:', data); + throw new Error('Unsupported chat format'); + }; + + const handleImportChats = () => { + const input = document.createElement('input'); + input.type = 'file'; + input.accept = '.json'; input.onchange = async (e) => { const file = (e.target as HTMLInputElement).files?.[0]; + if (!file || !db) { toast.error('Something went wrong'); return; @@ -330,7 +290,7 @@ export default function DataTab() { window.location.reload(); } catch (error) { if (error instanceof Error) { - logStore.logError('Failed to import chats', error); + logStore.logError('Failed to import chats:', error); toast.error('Failed to import chats: ' + error.message); } else { toast.error('Failed to import chats');