"use client"; import { useEffect, useState, useCallback } from "react"; import { AssetCard } from "@/components/asset-card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; interface Asset { id: string; type: string; platform?: string | null; format?: string | null; fileName: string; filePath: string; dimensions?: string | null; metadata?: string | null; status: string; campaign?: { name: string }; } interface AssetGalleryProps { campaignId?: string; onPushToPostiz?: (assetIds: string[]) => void; } export function AssetGallery({ campaignId, onPushToPostiz }: AssetGalleryProps) { const [assets, setAssets] = useState([]); const [selectedIds, setSelectedIds] = useState>(new Set()); const [filters, setFilters] = useState({ platform: "all", type: "all", status: "all", }); const [search, setSearch] = useState(""); const fetchAssets = useCallback(() => { const params = new URLSearchParams(); if (campaignId) params.set("campaignId", campaignId); if (filters.platform !== "all") params.set("platform", filters.platform); if (filters.type !== "all") params.set("type", filters.type); if (filters.status !== "all") params.set("status", filters.status); if (search) params.set("search", search); fetch(`/api/assets?${params}`) .then((r) => r.json()) .then(setAssets) .catch(() => {}); }, [campaignId, filters, search]); useEffect(() => { fetchAssets(); }, [fetchAssets]); async function handleStatusChange(id: string, status: string) { await fetch(`/api/assets/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status }), }); setAssets((prev) => prev.map((a) => (a.id === id ? { ...a, status } : a)) ); } function toggleSelect(id: string) { setSelectedIds((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); } async function bulkUpdateStatus(status: string) { await Promise.all( Array.from(selectedIds).map((id) => fetch(`/api/assets/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status }), }) ) ); setAssets((prev) => prev.map((a) => (selectedIds.has(a.id) ? { ...a, status } : a)) ); setSelectedIds(new Set()); } return (
{/* Filters */}
setSearch(e.target.value)} className="h-9 w-48" /> {selectedIds.size > 0 && (
{onPushToPostiz && ( )}
)}
{/* Grid */} {assets.length === 0 ? (

No assets yet. Launch a pipeline to generate content.

) : (
{assets.map((asset) => ( ))}
)}
); }