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 d4e121589..1ef238f79 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/index.tsx @@ -1,15 +1,18 @@ import { useEffect, useState } from "react"; +import ShortUniqueId from "short-unique-id"; import IconComponent from "../../../../../components/genericIconComponent"; import { Textarea } from "../../../../../components/ui/textarea"; import { CHAT_INPUT_PLACEHOLDER, CHAT_INPUT_PLACEHOLDER_SEND, } from "../../../../../constants/constants"; -import useFlowsManagerStore from "../../../../../stores/flowsManagerStore"; -import { FilePreviewType, chatInputType } from "../../../../../types/components"; -import { classNames } from "../../../../../utils/utils"; import { uploadFile } from "../../../../../controllers/API"; -import ShortUniqueId from "short-unique-id"; +import useFlowsManagerStore from "../../../../../stores/flowsManagerStore"; +import { + FilePreviewType, + chatInputType, +} from "../../../../../types/components"; +import { classNames } from "../../../../../utils/utils"; import FilePreview from "../filePreviewChat"; export default function ChatInput({ lockChat, @@ -47,25 +50,34 @@ export default function ChatInput({ if (items[i].type.indexOf("image") !== -1) { const blob = items[i].getAsFile(); if (blob) { - const id = uid() - setFiles([...files, { file: blob, loading: true, error: false,id}]); - uploadFile(blob, currentFlowId).then((res) => { - setFiles(prev=>{ - const newFiles = [...prev]; - const updatedIndex = newFiles.findIndex((file)=>file.id===id); - newFiles[updatedIndex].loading = false; - newFiles[updatedIndex].path = res.data.file_path; - return newFiles; + const id = uid(); + setFiles([ + ...files, + { file: blob, loading: true, error: false, id }, + ]); + uploadFile(blob, currentFlowId) + .then((res) => { + setFiles((prev) => { + 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) => { - setFiles(prev=>{ - const newFiles = [...prev]; - const updatedIndex = newFiles.findIndex((file)=>file.id===id); - newFiles[updatedIndex].loading = false; - newFiles[updatedIndex].error = true; - return newFiles; - }) - }); + .catch((err) => { + setFiles((prev) => { + const newFiles = [...prev]; + const updatedIndex = newFiles.findIndex( + (file) => file.id === id + ); + newFiles[updatedIndex].loading = false; + newFiles[updatedIndex].error = true; + return newFiles; + }); + }); } } } @@ -77,8 +89,11 @@ export default function ChatInput({ }; }, []); - function send(){ - sendMessage({repeat,files:files.map((file)=>file.path??"").filter((file)=>file!=="")}); + function send() { + sendMessage({ + repeat, + files: files.map((file) => file.path ?? "").filter((file) => file !== ""), + }); setFiles([]); } @@ -165,16 +180,20 @@ export default function ChatInput({
- { - files.map((file)=>( - { - setFiles(prev=>prev.filter((f)=>f.id!==file.id)) - // TODO: delete file on backend - }}/> - )) - } + {files.map((file) => ( + { + setFiles((prev) => prev.filter((f) => f.id !== file.id)); + // TODO: delete file on backend + }} + /> + ))}
- {/* + {/*