From 1f09459fa5cd436327481567537881ec2ea21d16 Mon Sep 17 00:00:00 2001 From: eduardruzga Date: Sun, 24 Nov 2024 12:05:22 +0200 Subject: [PATCH] Small change to make review easier --- app/components/chat/BaseChat.tsx | 436 ++++++++++++++++--------------- 1 file changed, 219 insertions(+), 217 deletions(-) diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index ab67167..b1d14ea 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -168,241 +168,243 @@ export const BaseChat = React.forwardRef( } }; - return ( - -
- {() => } -
-
- {!chatStarted && ( -
-

- Where ideas begin -

-

- Bring ideas to life in seconds or get help on existing projects. -

-
- )} + const chatImportButton = !chatStarted && ( +
+ { + 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); + + if (!Array.isArray(data.messages)) { + toast.error('Invalid chat file format'); + } + + await importChat(data.description, data.messages); + toast.success('Chat imported successfully'); + } 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'); + } + }} + /> +
+
+ +
+
+
+ ); + + const baseChat = ( +
+ {() => } +
+
+ {!chatStarted && ( +
+

+ Where ideas begin +

+

+ Bring ideas to life in seconds or get help on existing projects. +

+
+ )} +
+ + {() => { + return chatStarted ? ( + + ) : null; + }} +
- - {() => { - return chatStarted ? ( - - ) : null; - }} - + + + {provider && ( + updateApiKey(provider.name, key)} + /> + )} +
- - {provider && ( - updateApiKey(provider.name, key)} - /> - )} +