From 77b3089663312286d63861342c4d3b6daf26e799 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 17 Apr 2024 19:09:20 -0300 Subject: [PATCH] Update file preview functionality in chatInput component --- src/frontend/src/controllers/API/index.ts | 10 ++++++--- .../components/chatView/chatInput/index.tsx | 10 +++++++-- .../IOModal/components/chatView/index.tsx | 2 +- src/frontend/src/modals/IOModal/index.tsx | 7 ++++--- src/frontend/src/stores/flowStore.ts | 3 +++ src/frontend/src/types/components/index.ts | 6 +++--- src/frontend/src/types/zustand/flow/index.ts | 21 +++++++++++++++++++ src/frontend/src/utils/buildUtils.ts | 7 ++++++- 8 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 920335a97..202a120b9 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -922,12 +922,16 @@ export async function getVerticesOrder( export async function postBuildVertex( flowId: string, vertexId: string, - input_value: string + input_value: string, + files?: string[] ): Promise> { // input_value is optional and is a query parameter + const data = input_value ? { inputs: { input_value: input_value } } : undefined + if (data && files) { + data["files"] = files; + } return await api.post( - `${BASE_URL_API}build/${flowId}/vertices/${vertexId}`, - input_value ? { inputs: { input_value: input_value } } : undefined + `${BASE_URL_API}build/${flowId}/vertices/${vertexId}`, data ); } diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx index d33426169..d4e121589 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx @@ -54,6 +54,7 @@ export default function ChatInput({ const newFiles = [...prev]; const updatedIndex = newFiles.findIndex((file)=>file.id===id); newFiles[updatedIndex].loading = false; + newFiles[updatedIndex].path = res.data.file_path; return newFiles; }) }).catch((err) => { @@ -76,6 +77,11 @@ export default function ChatInput({ }; }, []); + function send(){ + sendMessage({repeat,files:files.map((file)=>file.path??"").filter((file)=>file!=="")}); + setFiles([]); + } + return (
@@ -88,7 +94,7 @@ export default function ChatInput({ !event.shiftKey && !event.nativeEvent.isComposing ) { - sendMessage(repeat); + send(); } }} rows={1} @@ -134,7 +140,7 @@ export default function ChatInput({ : "bg-chat-send text-background" )} disabled={lockChat || saveLoading} - onClick={(): void => sendMessage(repeat)} + onClick={(): void => send()} > {lockChat || saveLoading ? ( sendMessage(count)} + sendMessage={({repeat,files}) => sendMessage({repeat,files})} setChatValue={(value) => { setChatValue(value); }} diff --git a/src/frontend/src/modals/IOModal/index.tsx b/src/frontend/src/modals/IOModal/index.tsx index c81aecc35..7bafea90d 100644 --- a/src/frontend/src/modals/IOModal/index.tsx +++ b/src/frontend/src/modals/IOModal/index.tsx @@ -89,15 +89,16 @@ export default function IOModal({ } }, [open, currentFlow]); - async function sendMessage(count = 1): Promise { + async function sendMessage({repeat=1,files}:{repeat:number,files?:string[]}): Promise { if (isBuilding) return; setIsBuilding(true); setLockChat(true); setChatValue(""); - for (let i = 0; i < count; i++) { + for (let i = 0; i < repeat; i++) { await buildFlow({ input_value: chatValue, startNodeId: chatInput?.id, + files:files }).catch((err) => { console.error(err); setLockChat(false); @@ -382,7 +383,7 @@ export default function IOModal({