Files
deer-flow/frontend/src/components/workspace/artifacts/artifact-file-list.tsx

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-01-16 22:35:20 +08:00
import { DownloadIcon } from "lucide-react";
2026-01-17 00:02:03 +08:00
import { useCallback } from "react";
2026-01-16 22:35:20 +08:00
import { Button } from "@/components/ui/button";
import {
Card,
CardAction,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
2026-01-17 15:09:44 +08:00
import { urlOfArtifact } from "@/core/artifacts/utils";
import { getFileExtensionDisplayName, getFileName } from "@/core/utils/files";
2026-01-17 00:02:03 +08:00
import { cn } from "@/lib/utils";
2026-01-16 22:35:20 +08:00
2026-01-17 00:02:03 +08:00
import { useArtifacts } from "./context";
export function ArtifactFileList({
className,
files,
2026-01-17 15:09:44 +08:00
threadId,
2026-01-17 00:02:03 +08:00
}: {
className?: string;
files: string[];
2026-01-17 15:09:44 +08:00
threadId: string;
2026-01-17 00:02:03 +08:00
}) {
const { openArtifact } = useArtifacts();
const handleClick = useCallback(
(filepath: string) => {
openArtifact(filepath);
},
[openArtifact],
);
2026-01-16 22:35:20 +08:00
return (
2026-01-17 00:02:03 +08:00
<ul className={cn("flex w-full flex-col gap-4", className)}>
2026-01-16 22:35:20 +08:00
{files.map((file) => (
2026-01-17 00:02:03 +08:00
<Card
key={file}
2026-01-17 15:22:00 +08:00
className="cursor-pointer p-3"
2026-01-17 00:02:03 +08:00
onClick={() => handleClick(file)}
>
2026-01-17 15:22:00 +08:00
<CardHeader className="pr-2 pl-1">
2026-01-16 22:35:20 +08:00
<CardTitle>{getFileName(file)}</CardTitle>
2026-01-17 15:22:00 +08:00
<CardDescription className="text-xs">
2026-01-17 15:09:44 +08:00
{getFileExtensionDisplayName(file)} file
</CardDescription>
2026-01-16 22:35:20 +08:00
<CardAction>
2026-01-17 15:09:44 +08:00
<a
href={urlOfArtifact({
filepath: file,
threadId: threadId,
download: true,
})}
target="_blank"
onClick={(e) => e.stopPropagation()}
>
<Button variant="ghost">
<DownloadIcon className="size-4" />
Download
</Button>
</a>
2026-01-16 22:35:20 +08:00
</CardAction>
</CardHeader>
</Card>
))}
</ul>
);
}