From c20548965562e2206ca6e38d42b7cf217f67b290 Mon Sep 17 00:00:00 2001 From: iliasbo Date: Fri, 18 Sep 2026 15:11:31 +0200 Subject: [PATCH] fix: resolve filtered navigation bug in App component (#35) --- src/App.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ac6462d..8877cdb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import { useFilters } from "./controllers/useFilters"; import { PokemonList } from "./components/PokemonList/PokemonList"; import { FavoritePokemon } from "./components/FavoritePokemon/FavoritePokemon"; import { Filter } from "./components/Filter/Filter"; +import { GetNextFiltered, GetPrevFiltered } from "./controllers/pokemonController"; export default function App() { const [currentId, setCurrentId] = useState(1); @@ -21,12 +22,18 @@ export default function App() { queryFn: () => getPokemonByID(currentId), }); - const handlePrevious = () => { - setCurrentId((prev) => Math.max(1, prev - 1)); + const handlePrevious = async () => { + const prevPokemon = await GetPrevFiltered(currentId, filters); + if (prevPokemon) { + setCurrentId(prevPokemon.id); + } }; - const handleNext = () => { - setCurrentId((prev) => prev + 1); + const handleNext = async () => { + const nextPokemon = await GetNextFiltered(currentId, filters); + if (nextPokemon) { + setCurrentId(nextPokemon.id); + } }; const handleInputChange = (e: React.ChangeEvent) => { @@ -98,4 +105,4 @@ export default function App() { ); -} +} \ No newline at end of file