Spaces:
Paused
Paused
Download src/components/history-card.tsx from veltrixcode/retest: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/spaces/veltrixcode/retest/resolve/main/src/components/history-card.tsx
- Command line
-
hf download hf://spaces/veltrixcode/retest/src/components/history-card.tsx
-
curl -L -o history-card.tsx https://huggingface.co/spaces/veltrixcode/retest/resolve/main/src/components/history-card.tsx
3.22 kB
| "use client" | |
| import { useState } from "react" | |
| import Image from "next/image" | |
| import { useRouter } from "next/navigation" | |
| import { Button } from "@/components/ui/button" | |
| import { Download, Trash2, Loader2 } from "lucide-react" | |
| interface HistoryCardProps { | |
| generation: { | |
| id: string | |
| imageUrl: string | |
| prompt: string | |
| model: string | |
| createdAt: Date | |
| } | |
| } | |
| export function HistoryCard({ generation }: HistoryCardProps) { | |
| const router = useRouter() | |
| const [isDeleting, setIsDeleting] = useState(false) | |
| const handleDelete = async () => { | |
| if (!confirm("Delete this image? This cannot be undone.")) return | |
| setIsDeleting(true) | |
| try { | |
| const res = await fetch(`/api/generation/${generation.id}`, { | |
| method: "DELETE", | |
| }) | |
| if (!res.ok) throw new Error("Failed to delete") | |
| router.refresh() | |
| } catch (error) { | |
| console.error(error) | |
| alert("Failed to delete image") | |
| setIsDeleting(false) | |
| } | |
| } | |
| return ( | |
| <div className="group relative neo-brutalist bg-card rounded-none overflow-hidden aspect-square border-2 border-border"> | |
| {/* Action Buttons Overlay */} | |
| <div className="absolute top-2 right-2 z-10 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity"> | |
| <Button size="icon" variant="secondary" className="h-8 w-8 rounded-full border border-border shadow-sm" asChild> | |
| <a href={generation.imageUrl} download={`wild-art-${generation.id}.jpg`}> | |
| <Download className="h-4 w-4" /> | |
| </a> | |
| </Button> | |
| <Button | |
| size="icon" | |
| variant="destructive" | |
| className="h-8 w-8 rounded-full border border-border shadow-sm" | |
| onClick={handleDelete} | |
| disabled={isDeleting} | |
| > | |
| {isDeleting ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />} | |
| </Button> | |
| </div> | |
| <Image | |
| src={generation.imageUrl} | |
| alt={generation.prompt} | |
| fill | |
| className="object-cover transition-transform duration-700 group-hover:scale-110" | |
| unoptimized | |
| /> | |
| {/* Info Overlay */} | |
| <div className="absolute inset-x-0 bottom-0 bg-background/90 backdrop-blur-md p-4 border-t-2 border-border translate-y-full group-hover:translate-y-0 transition-transform duration-300"> | |
| <p className="font-bold text-sm line-clamp-2 mb-2 leading-tight" title={generation.prompt}>{generation.prompt}</p> | |
| <div className="flex items-center justify-between text-[10px] uppercase tracking-wider font-bold text-muted-foreground"> | |
| <span className="bg-secondary/10 px-2 py-0.5 rounded-sm text-secondary-foreground">{generation.model.split('/').pop()}</span> | |
| <span>{new Date(generation.createdAt).toLocaleDateString()}</span> | |
| </div> | |
| </div> | |
| </div> | |
| ) | |
| } | |