diff --git a/app/(main)/search/page.tsx b/app/(main)/search/page.tsx index 8b4bbd2..ef5a36b 100644 --- a/app/(main)/search/page.tsx +++ b/app/(main)/search/page.tsx @@ -482,28 +482,28 @@ function SearchPageContent() { }, [searchParams]) const handleGameChange = (game: string, checked: boolean) => { - setSelectedGames((prev) => { - const next = checked ? [...new Set([...prev, game])] : prev.filter((g) => g !== game) - replaceUrl((params) => { - params.delete("game") - for (const g of next) params.append("game", g) - resetPagination(params) - }) - return next + const next = checked + ? [...new Set([...selectedGames, game])] + : selectedGames.filter((item) => item !== game) + + setSelectedGames(next) + replaceUrl((params) => { + params.delete("game") + for (const value of next) params.append("game", value) + resetPagination(params) }) } const handlePriceChange = (type: "min" | "max", value: string) => { - setPriceRange((prev) => { - const next = { ...prev, [type]: value } - replaceUrl((params) => { - if (next.min) params.set("min", next.min) - else params.delete("min") - if (next.max) params.set("max", next.max) - else params.delete("max") - resetPagination(params) - }) - return next + const next = { ...priceRange, [type]: value } + + setPriceRange(next) + replaceUrl((params) => { + if (next.min) params.set("min", next.min) + else params.delete("min") + if (next.max) params.set("max", next.max) + else params.delete("max") + resetPagination(params) }) }