import { useActionQuery } from "@agent-native/core/client/hooks"; import { useT } from "@agent-native/core/client/i18n"; import { IconAlertTriangle, IconArrowUpRight, IconPhoto, } from "@tabler/icons-react"; import { useState } from "react"; import { Link } from "react-router"; import { AssetPreviewDialog } from "@/components/asset/AssetPreviewDialog"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; type DraftAsset = { id: string; title?: string | null; prompt?: string | null; mediaType?: string | null; mimeType?: string | null; thumbnailUrl?: string | null; previewUrl?: string | null; url?: string | null; }; const RECENT_DRAFTS_LIMIT = 5; export function RecentDraftsSection() { const t = useT(); const { data, isLoading, isError, isFetching, refetch } = useActionQuery( "list-draft-assets", { limit: RECENT_DRAFTS_LIMIT, }, ); const drafts = ((data as any)?.assets ?? []) as DraftAsset[]; const [previewAsset, setPreviewAsset] = useState(null); if (isError) { return (
{t("audit.unknownError")}
); } if (!isLoading && drafts.length === 0) return null; return (

{t("library.recentDrafts")}

{isLoading ? Array.from({ length: RECENT_DRAFTS_LIMIT }).map((_, index) => ( )) : drafts.map((draft) => ( ))}
setPreviewAsset(next as DraftAsset | null)} />
); } function DraftThumbnail({ draft }: { draft: DraftAsset }) { const t = useT(); const isVideo = draft.mediaType === "video" || draft.mimeType?.startsWith("video/"); const source = draft.thumbnailUrl ?? draft.previewUrl ?? draft.url ?? ""; if (isVideo && !draft.thumbnailUrl) { return (