fix: clear selection on pagination/search, add error handling for bulk sync

This commit is contained in:
2026-04-29 11:32:25 +08:00
parent 1215aca41a
commit caae92ca4f
@@ -93,6 +93,9 @@ export function GamesClient() {
setGames(json.data) setGames(json.data)
setTotal(json.total) setTotal(json.total)
} }
} else {
const errorData = await res.json().catch(() => ({ error: "Unknown error" }))
alert(`Sync failed: ${errorData.error || res.statusText}`)
} }
} catch (error) { } catch (error) {
console.error("Bulk sync failed:", error) console.error("Bulk sync failed:", error)
@@ -116,6 +119,7 @@ export function GamesClient() {
if (res.ok) { if (res.ok) {
const data = await res.json() const data = await res.json()
alert(data.message) alert(data.message)
setSelectedIds(new Set())
// Refresh games list // Refresh games list
const refreshRes = await fetch( const refreshRes = await fetch(
`/api/games?limit=${LIMIT}&offset=${offset}&search=${encodeURIComponent(search)}` `/api/games?limit=${LIMIT}&offset=${offset}&search=${encodeURIComponent(search)}`
@@ -125,6 +129,9 @@ export function GamesClient() {
setGames(json.data) setGames(json.data)
setTotal(json.total) setTotal(json.total)
} }
} else {
const errorData = await res.json().catch(() => ({ error: "Unknown error" }))
alert(`Sync failed: ${errorData.error || res.statusText}`)
} }
} catch (error) { } catch (error) {
console.error("Sync all failed:", error) console.error("Sync all failed:", error)
@@ -140,11 +147,13 @@ export function GamesClient() {
setSearch(value) setSearch(value)
setOffset(0) setOffset(0)
isSearchChangeRef.current = true isSearchChangeRef.current = true
setSelectedIds(new Set()) // Clear selection on search change
} }
const handlePrev = () => { const handlePrev = () => {
setOffset((prev) => Math.max(0, prev - LIMIT)) setOffset((prev) => Math.max(0, prev - LIMIT))
isSearchChangeRef.current = false isSearchChangeRef.current = false
setSelectedIds(new Set()) // Clear selection on page change
} }
const handleNext = () => { const handleNext = () => {