import { ButtonItem, ConfirmModal, Field, PanelSectionRow, showModal } from "@decky/ui"; import { useEffect, useState } from "react"; import { RiArrowDownSFill, RiArrowUpSFill } from "react-icons/ri"; import { GameTarget } from "../hooks/useGameConfiguration"; interface Props { targets: GameTarget[]; runningGame: GameTarget | null; onSelect: (appid: string) => void; onResetAll: () => Promise; } const CONFIGURED_COLLAPSED_KEY = "lsfg-configured-games-collapsed"; const AVAILABLE_COLLAPSED_KEY = "lsfg-available-games-collapsed"; function usePersistentCollapsed(key: string) { const [collapsed, setCollapsed] = useState(() => { try { return localStorage.getItem(key) === "true"; } catch { return false; } }); useEffect(() => { try { localStorage.setItem(key, String(collapsed)); } catch { // Persisting the view preference is optional. } }, [collapsed, key]); return [collapsed, () => setCollapsed((value) => !value)] as const; } function GameGroup({ title, games, collapsed, onToggle, onSelect, }: { title: string; games: GameTarget[]; collapsed: boolean; onToggle: () => void; onSelect: (appid: string) => void; }) { if (games.length === 0) return null; return ( <> {collapsed ? : } {title} ({games.length}) {!collapsed && games.map((game) => ( onSelect(game.appid)} highlightOnFocus /> ))} ); } export function GameConfigurationSelector({ targets, runningGame, onSelect, onResetAll }: Props) { const sortGames = (games: GameTarget[]) => [...games].sort((a, b) => { if (a.appid === runningGame?.appid) return -1; if (b.appid === runningGame?.appid) return 1; return a.name.localeCompare(b.name); }); const configuredGames = sortGames(targets.filter((game) => game.configured)); const availableGames = sortGames(targets.filter((game) => !game.configured)); const [configuredCollapsed, toggleConfigured] = usePersistentCollapsed(CONFIGURED_COLLAPSED_KEY); const [availableCollapsed, toggleAvailable] = usePersistentCollapsed(AVAILABLE_COLLAPSED_KEY); const confirmResetAll = () => { showModal( void onResetAll()} onCancel={() => {}} />, ); }; return ( <> {targets.length === 0 && ( )} target.configured)} > Remove all profiles ); }