diff --git a/src/App.css b/src/App.css index a3aab55..168968a 100644 --- a/src/App.css +++ b/src/App.css @@ -404,6 +404,17 @@ cursor: pointer; } +.pokemon-card-title { + display: flex; + align-items: center; + gap: 4px; +} + +.pokemon-card-title .favorite-toggle { + width: auto; + padding: 0 4px; +} + .pokemon-card-header { display: flex; align-items: center; diff --git a/src/App.tsx b/src/App.tsx index af8c407..717f97e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -72,6 +72,8 @@ function App() { str.charAt(0).toUpperCase() + str.slice(1); type PokemonDetailsProps = { selectedPokemonId: number | null; setSelectedPokemonId: Dispatch>; + isFavorite: (id: number) => boolean; + toggleFavorite: (pokemon: Pokemon) => void; }; function PokemonDetails({ selectedPokemonId, setSelectedPokemonId, + isFavorite, + toggleFavorite, }: PokemonDetailsProps) { // TanStack Query is used to fetch the details of the selected Pokémon based on its ID. const { @@ -47,6 +51,9 @@ function PokemonDetails({ (_, rowIndex) => selectedPokemon.stats.slice(rowIndex * 3, rowIndex * 3 + 3) ); + const favorite = isFavorite(selectedPokemon.id); + const name = capitalize(selectedPokemon.name); + return ( - - {capitalize(selectedPokemon.name)}{' '} - #{selectedPokemon.id} - + + + {capitalize(selectedPokemon.name)}{' '} + #{selectedPokemon.id} + + + toggleFavorite({ + id: selectedPokemon.id, + name: selectedPokemon.name, + imageUrl: selectedPokemon.imageUrl, + apiUrl: pokemonApiUrl(selectedPokemon.id), + }) + } + aria-label={ + favorite + ? `Fjern ${name} fra favoritter` + : `Legg ${name} til favoritter` + } + aria-pressed={favorite} + > + ★ + + {capitalize(selectedPokemon.generation.replace('-', ' '))}
{capitalize(selectedPokemon.generation.replace('-', ' '))}