add gameview navigation

This commit is contained in:
Garret Patti
2026-04-17 23:55:33 -04:00
parent b774cba046
commit b2e9df8ab8
7 changed files with 108 additions and 28 deletions

View File

@@ -72,7 +72,10 @@ export default function GamesView({ libraryId }: Props) {
const [selectedTagIds, setSelectedTagIds] = useState<Set<string>>(new Set())
const [assignments, setAssignments] = useState<Record<string, string[]>>({})
const [filterRefreshKey, setFilterRefreshKey] = useState(0)
const [showFilters, setShowFilters] = useState(true)
const [showFilters, setShowFilters] = useState(
() => typeof window !== 'undefined' && window.innerWidth >= 768
)
const [selectedGameIndex, setSelectedGameIndex] = useState<number | null>(null)
const toggleTag = (tagId: string) =>
setSelectedTagIds((prev) => {
@@ -147,6 +150,7 @@ export default function GamesView({ libraryId }: Props) {
})
const filtersActive = search !== '' || selectedTagIds.size > 0
const filteredGames = filtered.filter((i): i is Game => !('games' in i))
return (
<>
@@ -220,7 +224,7 @@ export default function GamesView({ libraryId }: Props) {
<GameCard
key={item.id}
game={item}
onClick={() => setSelected(item)}
onClick={() => { setSelected(item); setSelectedGameIndex(filteredGames.indexOf(item)) }}
/>
)
)}
@@ -231,11 +235,18 @@ export default function GamesView({ libraryId }: Props) {
<GameDetailModal
game={selected}
libraryId={libraryId}
onClose={() => setSelected(null)}
onClose={() => { setSelected(null); setSelectedGameIndex(null) }}
onPrev={selectedGameIndex !== null && selectedGameIndex > 0
? () => { const g = filteredGames[selectedGameIndex - 1]; setSelected(g); setSelectedGameIndex(selectedGameIndex - 1) }
: undefined}
onNext={selectedGameIndex !== null && selectedGameIndex < filteredGames.length - 1
? () => { const g = filteredGames[selectedGameIndex + 1]; setSelected(g); setSelectedGameIndex(selectedGameIndex + 1) }
: undefined}
onTagsChanged={() => { setFilterRefreshKey((k) => k + 1); fetchAssignments() }}
onCoverUploaded={() => fetchGames(true)}
onDeleted={() => {
setSelected(null)
setSelectedGameIndex(null)
fetchGames()
fetchAssignments()
}}