import type { Message } from 'ai'; import { toast } from 'react-toastify'; import { ImportFolderButton } from '~/components/chat/ImportFolderButton'; import { Button } from '~/components/ui/Button'; import { classNames } from '~/utils/classNames'; type ChatData = { messages?: Message[]; // Standard Bolt format description?: string; // Optional description }; export function ImportButtons(importChat: ((description: string, messages: Message[]) => Promise) | undefined) { return (
{ const file = e.target.files?.[0]; if (file && importChat) { try { const reader = new FileReader(); reader.onload = async (e) => { try { const content = e.target?.result as string; const data = JSON.parse(content) as ChatData; // Standard format if (Array.isArray(data.messages)) { await importChat(data.description || 'Imported Chat', data.messages); toast.success('Chat imported successfully'); return; } toast.error('Invalid chat file format'); } catch (error: unknown) { if (error instanceof Error) { toast.error('Failed to parse chat file: ' + error.message); } else { toast.error('Failed to parse chat file'); } } }; reader.onerror = () => toast.error('Failed to read chat file'); reader.readAsText(file); } catch (error) { toast.error(error instanceof Error ? error.message : 'Failed to import chat'); } e.target.value = ''; // Reset file input } else { toast.error('Something went wrong'); } }} />
); }