import { CopyIcon, DownloadIcon, SquareArrowOutUpRightIcon, XIcon, } from "lucide-react"; import { useMemo } from "react"; import { toast } from "sonner"; import { Artifact, ArtifactAction, ArtifactActions, ArtifactContent, ArtifactHeader, ArtifactTitle, } from "@/components/ai-elements/artifact"; import { Select, SelectItem } from "@/components/ui/select"; import { SelectContent, SelectGroup, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useArtifactContent } from "@/core/artifacts/hooks"; import { urlOfArtifact } from "@/core/artifacts/utils"; import { checkCodeFile, getFileName } from "@/core/utils/files"; import { cn } from "@/lib/utils"; import { useArtifacts } from "./context"; import { FileViewer } from "./file-viewer"; export function ArtifactFileDetail({ className, filepath, threadId, }: { className?: string; filepath: string; threadId: string; }) { const { artifacts, setOpen, select } = useArtifacts(); const { isCodeFile } = useMemo(() => checkCodeFile(filepath), [filepath]); const { content } = useArtifactContent({ threadId, filepath, enabled: isCodeFile, }); return (
{isCodeFile && ( { try { await navigator.clipboard.writeText(content ?? ""); toast.success("Copied to clipboard"); } catch (error) { toast.error("Failed to copy to clipboard"); console.error(error); } }} tooltip="Copy content to clipboard" /> )} console.log("Download")} tooltip="Download file" /> setOpen(false)} tooltip="Close" />
); }