diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx index bda6e64d5..f73c9aa44 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx @@ -16,6 +16,7 @@ import useFlowStore from "../../../../../stores/flowStore"; import { chatMessagePropsType } from "../../../../../types/components"; import { classNames, cn } from "../../../../../utils/utils"; import FileCard from "../fileComponent"; +import formatFileName from "../filePreviewChat/utils/format-file-name"; export default function ChatMessage({ chat, @@ -329,7 +330,7 @@ dark:prose-invert" onClick={() => setShowFile(!showFile)} className="flex cursor-pointer gap-2 text-sm text-muted-foreground" > - {file.name} + {formatFileName(file.name, 50)} diff --git a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx index c21688247..f15c6b63e 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx @@ -16,7 +16,26 @@ export default function FileCard({ fileType, showFile = true, }: fileCardPropsType): JSX.Element | undefined { - const handleDownload = (): void => {}; + const handleDownload = async (): Promise => { + try { + const response = await fetch( + `${BACKEND_URL.slice(0, BACKEND_URL.length - 1)}${BASE_URL_API}files/download/${content}`, + ); + const blob = await response.blob(); + const url = URL.createObjectURL(blob); + + const link = document.createElement("a"); + link.href = url; + link.setAttribute("download", fileName); // Set the filename + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + URL.revokeObjectURL(url); // Clean up the URL object + } catch (error) { + console.error("Failed to download file:", error); + } + }; const [isHovered, setIsHovered] = useState(false); const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId); function handleMouseEnter(): void { @@ -37,7 +56,7 @@ export default function FileCard({ onMouseLeave={handleMouseLeave} style={{ display: "inline-block" }} > - + {isHovered && ( @@ -77,10 +98,18 @@ export default function FileCard({ File - + {isHovered && ( + + + + + + )} ); }