feat(mvp): glue components together, repair the build and add filtering #26
+2,178
−393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves #6 and #12.
This is #23, #24 and #25 rolled into one branch so it can go to
mainin a single review. Commit history is kept, so the four commits can still be read separately.mainhas not moved sinceissue-6branched, so this merges cleanly.What is in it
1.
chore: glue components togetherandfix: delete file that was added by accident(@thomhet, originally #23)Combines the components in App, centralises variables and util functions, adds the responsive layout, colours the type badges.
2.
fix(mvp): repair build errors and fetch through TanStack Query(originally #24)npm run builddid not complete onissue-6: 14 TypeScript errors and 6 lint errors. The tests passed, which is why it read as green. Fixed here:SORT_OPTIONShad been removed whileisSortOptionstill called it, andsortwas written with an unchecked cast, so a corrupt value in session storage passed straight through. Validation restored.GetManypushed failed fetches into aPokemonData[]asnull, which the favorites view then crashed on. It fetches in parallel now and drops failures.matchesFiltertook one argument but was called with two inGetPrevFilteredandGetNextFiltered.FavoritePokemoncalled.sort()andonSelectPokemon()on props typed as optional, and sorted the caller's array in place.PokemonCardandfilters.ts, andtotalreassigned during render.Behaviour, on top of the build:
useStateand the card never remounts. Confirmed with a render test, fixed by resetting on id change.PokemonListanduseFavoritesfetched with plainuseStateanduseEffect. Both go through TanStack Query now, which is a requirement and also what was causing the repeated refetching.divandliwithonClick, so neither could be reached by keyboard. Both are buttons with focus outlines.Apprendered a secondid="root"inside the one inindex.html. Ids have to be unique, so the layout div is.app-layout.3.
feat(filters): add filter component that reloads the pokemon list(originally #25)The filter view from #12. Sort by id, filter on any number of types, and only-show-favorites. Collapsed behind a
details/summaryso eighteen type checkboxes do not crowd the header row, which also gives keyboard and screen reader support without a third party component. Rules persist in session storage throughuseFilters.sortandonlyFavoriteswere in the model but read nowhere, so they did nothing. Both are applied now. The favorites view reuses whatuseFavoritesalready fetched rather than calling the api again.Sorting is limited to
id-ascandid-desc. Sorting on name would mean fetching every pokemon up front just to learn the names, which the fetch-on-the-fly rule does not allow.Checks
issue-6tsc -beslint .prettier --checkvitest runvite buildPokemonList.test.tsxhad been deleted in #23 and is restored here.Known, not fixed in this PR
GetNextFilteredandGetPrevFilteredwalk one id at a time, fetching every pokemon until one matches. With a sparse type filter, filling an 11 item list is a lot of sequential requests, and a filter that matches nothing scans all 1025 in both directions. That is the "no unnecessary calls to the REST API" criterion. PokeAPI's/type/{name}returns every pokemon of a type in one request and looks like the right fix, but it is a large enough change that it belongs in its own issue.Still open elsewhere: #10 tests (
FavoritePokemonandapi/pokemon.tshave none), #11 css polish, #13 deploy, #14 readme.