import Link from "next/link"; import { formatDistance } from "date-fns"; import { Download, EllipsisVertical, Lock, Settings, Trash, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { ProjectType } from "@/types"; import { toast } from "sonner"; import { useUser } from "@/hooks/useUser"; // from-red-500 to-red-500 // from-yellow-500 to-yellow-500 // from-green-500 to-green-500 // from-purple-500 to-purple-500 // from-blue-500 to-blue-500 // from-pink-500 to-pink-500 // from-gray-500 to-gray-500 // from-indigo-500 to-indigo-500 export function ProjectCard({ project, onDelete, }: { project: ProjectType; onDelete: () => void; }) { const { token } = useUser(); const handleDelete = () => { if ( confirm( "Are you sure you want to delete this project? This action cannot be undone." ) ) { onDelete(); } }; const handleDownload = async () => { try { toast.info("Preparing download..."); const response = await fetch( `/deepsite/api/me/projects/${project.name}/download`, { credentials: "include", headers: { Accept: "application/zip", Authorization: `Bearer ${token}`, }, } ); if (!response.ok) { const error = await response .json() .catch(() => ({ error: "Download failed" })); toast.error(error.error || "Failed to download project"); return; } const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = `${project.name.replace(/\//g, "-")}.zip`; document.body.appendChild(link); link.click(); document.body.removeChild(link); window.URL.revokeObjectURL(url); toast.success("Download started!"); } catch (error) { console.error("Download error:", error); toast.error("Failed to download project"); } }; // from-gray-600 to-gray-600 // from-blue-600 to-blue-600 // from-green-600 to-green-600 // from-yellow-600 to-yellow-600 // from-purple-600 to-purple-600 // from-pink-600 to-pink-600 // from-red-600 to-red-600 // from-orange-600 to-orange-600 return (
{project.cardData?.emoji}
{project?.cardData?.title ?? project.name}
Updated{" "} {formatDistance( new Date(project.updatedAt || Date.now()), new Date(), { addSuffix: true, } )}