/** * Archive, as an overlay rather than a footer. * * It used to sit in the card's footer, which is where a reader's eye lands * after the title — so the most destructive control on the page was competing * with the content for attention, for the majority of viewers who cannot even * use it. It is now a sibling of the play button (never a descendant: a button * inside a button is invalid and Firefox drops the inner one) and only appears * once an admin has asked to manage. */ import { useState } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Trash2 } from 'lucide-react'; import { toast } from 'sonner'; import { api } from '@/lib/api'; import { cn } from '@/components/ui'; export function ArchiveControl({ id, title, className, }: { id: string; title: string; className?: string; }) { const queryClient = useQueryClient(); const [confirming, setConfirming] = useState(false); const archive = useMutation({ mutationFn: () => api(`/api/learn/resources/${id}`, { method: 'DELETE' }), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ['learn'] }); toast.success(`Archived “${title}”.`); }, onError: (error: unknown) => { setConfirming(false); toast.error(error instanceof Error ? error.message : 'Could not archive that video.'); }, }); return ( ); }