import { CircleNotch, FileCode, FileCsv, FileDoc, FileHtml, FileText, FileImage, FilePdf, WarningOctagon, X, } from "@phosphor-icons/react"; import { REMOVE_ATTACHMENT_EVENT } from "../../DnDWrapper"; import { Tooltip } from "react-tooltip"; /** * @param {{attachments: import("../../DnDWrapper").Attachment[]}} * @returns */ export default function AttachmentManager({ attachments }) { if (attachments.length === 0) return null; return (
{attachments.map((attachment) => ( ))}
); } /** * @param {{attachment: import("../../DnDWrapper").Attachment}} */ function AttachmentItem({ attachment }) { const { uid, file, status, error, document, type, contentString } = attachment; const { iconBgColor, Icon } = displayFromFile(file); function removeFileFromQueue() { window.dispatchEvent( new CustomEvent(REMOVE_ATTACHMENT_EVENT, { detail: { uid, document } }) ); } if (status === "in_progress") { return (

{file.name}

Uploading...

); } if (status === "failed") { return ( <>

{file.name}

{error ?? "File not embedded!"}

); } if (type === "attachment") { return ( <>
{contentString ? ( {`Preview ) : (
)}

{file.name}

Image attached!

); } return ( <>

{file.name}

{status === "embedded" ? "File embedded!" : "Added as context!"}

); } /** * @param {File} file * @returns {{iconBgColor:string, Icon: React.Component}} */ function displayFromFile(file) { const extension = file?.name?.split(".")?.pop()?.toLowerCase() ?? "txt"; switch (extension) { case "pdf": return { iconBgColor: "bg-magenta", Icon: FilePdf }; case "doc": case "docx": return { iconBgColor: "bg-royalblue", Icon: FileDoc }; case "html": return { iconBgColor: "bg-purple", Icon: FileHtml }; case "csv": case "xlsx": return { iconBgColor: "bg-success", Icon: FileCsv }; case "json": case "sql": case "js": case "jsx": case "cpp": case "c": return { iconBgColor: "bg-warn", Icon: FileCode }; case "png": case "jpg": case "jpeg": return { iconBgColor: "bg-royalblue", Icon: FileImage }; default: return { iconBgColor: "bg-royalblue", Icon: FileText }; } }