import { useQueryClient } from "@tanstack/react-query"; import { motion, stagger } from "motion/react"; import type { FC } from "react"; import { getGetLibraryQueryKey, useDeleteCustomGame, useGetLibrary, } from "@/api/gen/library/library"; import type { GameEntry } from "@/api/gen/model/gameEntry"; import { QueryState } from "@/components/query-state"; import { Card, CardContent } from "@/components/ui/card"; import type { Loadable } from "@/lib/query"; import { m } from "@/paraglide/messages"; import { GameCard } from "./GameCard"; import { customId } from "./helpers"; /** * Container: the library OVERVIEW — owns the listing query and per-card delete. * Editing is escalated to the parent (it opens the separate add/edit form), so * this subsection knows nothing about the form beyond firing `onEdit`. */ export const LibraryGridSection: FC<{ onEdit: (entry: GameEntry) => void }> = ({ onEdit, }) => { const qc = useQueryClient(); const library = useGetLibrary(); const remove = useDeleteCustomGame(); const onDelete = async (entry: GameEntry) => { if (!confirm(m.library_delete_confirm())) return; await remove .mutateAsync({ id: customId(entry) }) .then(() => qc.invalidateQueries({ queryKey: getGetLibraryQueryKey() })); }; return ( ); }; /** The poster grid (with empty + loading/error states). */ export const LibraryGrid: FC<{ library: Loadable; onEdit: (entry: GameEntry) => void; onDelete: (entry: GameEntry) => void; isDeleting: boolean; }> = ({ library, onEdit, onDelete, isDeleting }) => { const games = library.data ?? []; return ( {games.length === 0 ? ( {m.library_empty()} ) : ( {games.map((game) => ( onEdit(game)} onDelete={() => onDelete(game)} deleting={isDeleting} /> ))} )} ); };