diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 425fcf4a..13a00436 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -33,10 +33,12 @@ function App() { const [favorites, setFavorites] = useState>(new Set()); const [view, setView] = useState('list'); const [showFavorites, setShowFavorites] = useState(false); - const navigate = useNavigate(); + const navigate = useNavigate(); + const { pathname } = useLocation(); // Søk, filtre og sortering vises på listesiden /spill. Forsiden / har rader - const onListPage = useLocation().pathname === '/spill'; - + const onListPage = pathname === '/spill'; + // Forsiden har sitt eget store søkefelt, så toppfeltet viser ikke søk der + const onHomePage = pathname === '/'; // Søket i hovedlista. Settes først når brukeren trykker Enter, ikke for hver bokstav // (forslagene i søkefeltet tar seg av det), så lista og pagineringen ikke hopper const [query, setQuery] = useState(''); @@ -202,10 +204,12 @@ function App() { favoritesCount={favorites.size} showFavorites={showFavorites && onListPage} onToggleFavorites={handleToggleFavorites} + showSearch={!onHomePage} + initialSearch={query} /> - {/* Forsiden med rader */} + {/* Forsiden med søk øverst og rader */} } /> diff --git a/frontend/src/components/GameSearch/GameSearch.tsx b/frontend/src/components/GameSearch/GameSearch.tsx index 74fbedad..8f928476 100644 --- a/frontend/src/components/GameSearch/GameSearch.tsx +++ b/frontend/src/components/GameSearch/GameSearch.tsx @@ -13,6 +13,8 @@ interface GameSearchProps { onSearch: (term: string) => void; /** Brukeren valgte ett spill i forslagslista */ onSelectGame: (game: Suggestion) => void; + /** Teksten feltet starter med, f.eks. søket som gjelder når feltet vises på nytt */ + initialValue?: string; } /** @@ -24,8 +26,8 @@ interface GameSearchProps { * Følger WAI-ARIA-mønsteret "combobox med listbox". */ -export function GameSearch({ onSearch, onSelectGame }: GameSearchProps) { - const [input, setInput] = useState(''); +export function GameSearch({ onSearch, onSelectGame, initialValue = '' }: GameSearchProps) { + const [input, setInput] = useState(initialValue); const [open, setOpen] = useState(false); const [active, setActive] = useState(-1); // markert forslag, -1 = ingen const id = useId(); diff --git a/frontend/src/components/Header/Header.tsx b/frontend/src/components/Header/Header.tsx index 1680e263..73abb6f6 100644 --- a/frontend/src/components/Header/Header.tsx +++ b/frontend/src/components/Header/Header.tsx @@ -14,6 +14,8 @@ interface HeaderProps { onToggleFavorites: () => void; onHome: () => void; searchResetKey: number; + showSearch: boolean; + initialSearch: string; } /** @@ -28,15 +30,24 @@ export function Header({ favoritesCount, showFavorites, onToggleFavorites, + showSearch, + initialSearch, }: HeaderProps) { const { user, logOut } = useAuth(); const location = useLocation(); return (
-
- -
+ {showSearch && ( +
+ +
+ )}