feat(games): fetch games from backend

This commit is contained in:
zetaloop
2026-02-28 16:23:30 +08:00
parent 6dd21e1090
commit f4365668ab
5 changed files with 96 additions and 14 deletions
+19 -1
View File
@@ -374,7 +374,7 @@ function FilterSection({
function SearchPageContent() {
const searchParams = useSearchParams()
const router = useRouter()
const games = listGames()
const [games, setGames] = useState<Game[]>([])
const [searchQuery, setSearchQuery] = useState(searchParams.get("q") || "")
const [selectedGames, setSelectedGames] = useState<string[]>(() => {
@@ -396,6 +396,24 @@ function SearchPageContent() {
const [hasLoaded, setHasLoaded] = useState(false)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
let cancelled = false
listGames()
.then((items) => {
if (cancelled) return
setGames(items)
})
.catch(() => {
if (cancelled) return
setGames([])
})
return () => {
cancelled = true
}
}, [])
const replaceUrl = useCallback(
(updater: (params: URLSearchParams) => void) => {
const params = new URLSearchParams(searchParams.toString())