From 568f4f1bc5f73144be435f423aea14fc1ec02532 Mon Sep 17 00:00:00 2001
From: SivertEikrem
Date: Fri, 18 Sep 2026 15:27:48 +0200
Subject: [PATCH] added favorites to playing-cards
---
README.md | 6 +++---
src/App.css | 28 ++++++++++++++++++++++++++++
src/App.tsx | 42 +++++++++++++++++++++++-------------------
src/PokemonModal.tsx | 38 ++++++++++++++++++++++++++++++++++++++
src/main.tsx | 2 +-
5 files changed, 93 insertions(+), 23 deletions(-)
create mode 100644 src/PokemonModal.tsx
diff --git a/README.md b/README.md
index 3c4c4ff..7112c3c 100644
--- a/README.md
+++ b/README.md
@@ -30,9 +30,9 @@ sudo rsync -av --delete dist/ /var/www/html/project1/
echo "Deploy ferdig!"
```
-
## Prettier use
+
```
npm install
-npm run format
-```
\ No newline at end of file
+npm run format
+```
diff --git a/src/App.css b/src/App.css
index d27aa90..98077d5 100644
--- a/src/App.css
+++ b/src/App.css
@@ -319,3 +319,31 @@
padding-bottom: 4px;
}
}
+
+.modal-overlay {
+ position: fixed;
+ inset: 0;
+ background: rgba(0, 0, 0, 0.6);
+ display: flex;
+ align-items: center;
+ z-index: 100;
+}
+
+.modal-content {
+ background: #fff;
+ border-radius: 12px;
+ padding: 2rem;
+ position: relative;
+ max-width: 320px;
+ text-align: center;
+}
+
+.modal-close {
+ position: absolute;
+ top: 0.5rem;
+ right: 0.5rem;
+ border: none;
+ background: none;
+ font-size: 1.5rem;
+ cursor: pointer;
+}
diff --git a/src/App.tsx b/src/App.tsx
index 7bd108f..5989eee 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -5,6 +5,8 @@ import { listAllPokemon } from './Api';
import { useFavorites } from './useFavorites';
import FavoritesSidebar from './FavoritesSidebar';
import './App.css';
+import type { Pokemon } from './Api';
+import PokemonModal from './PokemonModal';
const SEARCH_STORAGE_KEY = 'pokemon-search';
@@ -14,7 +16,7 @@ function capitalize(text: string): string {
function App() {
const [query, setQuery] = useState(
- () => sessionStorage.getItem(SEARCH_STORAGE_KEY) ?? '',
+ () => sessionStorage.getItem(SEARCH_STORAGE_KEY) ?? ''
);
// TanStack Query håndterer henting og caching av Pokémon-lista.
@@ -29,19 +31,19 @@ function App() {
});
const [submittedQuery, setSubmittedQuery] = useState(
- () => sessionStorage.getItem(SEARCH_STORAGE_KEY) ?? '',
+ () => sessionStorage.getItem(SEARCH_STORAGE_KEY) ?? ''
);
const [error, setError] = useState('');
const { favorites, isFavorite, toggleFavorite } = useFavorites();
+ const [selectedPokemon, setSelectedPokemon] = useState(null);
+
const pokemon = submittedQuery
? allPokemon
- .filter((entry) =>
- entry.name.includes(submittedQuery.toLowerCase()),
- )
- .slice(0, 24)
+ .filter((entry) => entry.name.includes(submittedQuery.toLowerCase()))
+ .slice(0, 24)
: [];
function handleSearch(event: FormEvent) {
@@ -90,27 +92,21 @@ function App() {
)}
- {!isError && error && (
- {error}
- )}
+ {!isError && error && {error}
}
- {!isError &&
- !error &&
+ {!isError &&
+ !error &&
!isPending &&
- submittedQuery &&
+ submittedQuery &&
pokemon.length === 0 && (
Fant ingen Pokémon som matcher «{submittedQuery}».
)}
- {!isError &&
- !error &&
- !isPending &&
- !submittedQuery && (
- Søkeresultatene dine vises her.
- )}
-
+ {!isError && !error && !isPending && !submittedQuery && (
+ Søkeresultatene dine vises her.
+ )}
{pokemon.map((entry) => (
@@ -145,6 +141,14 @@ function App() {
+ {selectedPokemon && (
+
setSelectedPokemon(null)}
+ />
+ )}
>
);
}
diff --git a/src/PokemonModal.tsx b/src/PokemonModal.tsx
new file mode 100644
index 0000000..e89fbc7
--- /dev/null
+++ b/src/PokemonModal.tsx
@@ -0,0 +1,38 @@
+import type { Pokemon } from './Api';
+
+function capitalize(text: string): string {
+return text.charAt(0).toUpperCase() + text.slice(1);
+}
+
+type PokemonModalProps = {
+pokemon: Pokemon;
+isFavorite: boolean;
+onToggleFavorite: (pokemon: Pokemon) => void;
+onClose: () => void;
+};
+
+function PokemonModal({ pokemon, isFavorite, onToggleFavorite, onClose }: PokemonModalProps) {
+return (
+
+
event.stopPropagation()}>
+
+

+
{capitalize(pokemon.name)}
+
#{pokemon.id}
+
+
+
+
+);
+}
+
+export default PokemonModal;
diff --git a/src/main.tsx b/src/main.tsx
index eb0dde4..32f177e 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,6 +1,6 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import './index.css';
import App from './App.tsx';