import { deleteGameMutation, gameInvalidationQuery } from "@/mainview/scripts/queries/romm"; import { FocusContext, setFocus, useFocusable } from "@noriginmedia/norigin-spatial-navigation"; import { useMutation } from "@tanstack/react-query"; import { ContextList, DialogEntry, useContextDialog } from "../ContextDialog"; import { getErrorMessage } from "react-error-boundary"; import toast from "react-hot-toast"; import { Settings, Trash, Trophy } from "lucide-react"; import MainActions from "./MainActions"; import ActionButton from "./ActionButton"; import { useLocalStorage } from "usehooks-ts"; import FocusTooltip from "../FocusTooltip"; import { useBlocker, useRouter } from "@tanstack/react-router"; function AchievementsInfo (data: { game: FrontEndGameTypeDetailed; } & InteractParams) { if (!data.game.achievements) { return false; } return
{`${data.game.achievements.unlocked}/${data.game.achievements.total}`}
; } export default function ActionButtons (data: { game?: FrontEndGameTypeDetailed, source: string, id: string; }) { const [, setDetailsSection] = useLocalStorage('details-section', 'screenshots'); const { ref, focusKey, hasFocusedChild } = useFocusable({ focusKey: 'actions', forceFocus: true, trackChildren: true, preferredChildFocusKey: 'mainAction' }); const router = useRouter(); const deleteMutation = useMutation({ ...deleteGameMutation({ id: data.id, source: data.source }), onSuccess: (d, v, r, ctx) => { ctx.client.invalidateQueries(gameInvalidationQuery(data.id, data.source)).then(() => router.history.back()); }, onError (error) { toast.error(getErrorMessage(error) ?? "Error While Deleting"); } }); useBlocker({ shouldBlockFn: () => deleteMutation.isPending }); const contextOptions: DialogEntry[] = []; if (data.game?.local) { if (deleteMutation.isPending) { contextOptions.push({ id: 'delete', icon: , content: "Deleting", type: 'error' }); } else { contextOptions.push({ id: 'delete', action: () => { deleteMutation.mutate(); }, icon: , content: "Delete", type: 'error' }); } } const { setOpen, dialog: settingsDialog } = useContextDialog("settings-context", { content: , canClose: !deleteMutation.isPending }); return
{data.game && { setDetailsSection("achievements"); if (data.game?.achievements?.entires[0]) { setFocus(data.game.achievements.entires[0].id); } }} />} setOpen(true, 'settings')} type="base" id="settings" icon={} > {settingsDialog}
; }