From c089bbe82d4b3cdae5baf5aabc5298256627d4e3 Mon Sep 17 00:00:00 2001 From: Alessandro Bortolin Date: Fri, 12 Jul 2024 16:03:54 +0200 Subject: [PATCH] Improve search --- frontend/app/navbar.tsx | 71 +++++++++++++--------------------- frontend/app/search/page.tsx | 34 ++++++++++++++-- frontend/components/search.tsx | 30 ++++++++------ 3 files changed, 74 insertions(+), 61 deletions(-) diff --git a/frontend/app/navbar.tsx b/frontend/app/navbar.tsx index 9af4980d73..d7a9d2a29c 100644 --- a/frontend/app/navbar.tsx +++ b/frontend/app/navbar.tsx @@ -2,12 +2,11 @@ import Link from "next/link"; import { Navbar as BaseNavbar, - NavbarMenu as BaseNavbarMenu, - Dropdown, - DropdownButton, - DropdownMenu, + NavbarBrand, + NavbarContent, + NavbarMenu, + NavbarMenuItem, } from "@olinfo/react-components"; -import { MenuIcon } from "lucide-react"; import { Image } from "~/components/image"; import { Search } from "~/components/search"; @@ -20,50 +19,32 @@ import logoLight from "./oiistats-light.png?h=32"; export function Navbar() { return ( -
- - - - - - - - + - Logo OII stats + Logo OII stats -
- - - -
-
-
+ + + + Home + + + Edizioni + + + Hall of Fame + + + Regioni + + + Problemi + + + -
+
); } - -function NavbarMenu() { - return ( - <> -
  • - Home -
  • -
  • - Edizioni -
  • -
  • - Hall of Fame -
  • -
  • - Regioni -
  • -
  • - Problemi -
  • - - ); -} diff --git a/frontend/app/search/page.tsx b/frontend/app/search/page.tsx index c0f4aa6b5a..73eeb43961 100644 --- a/frontend/app/search/page.tsx +++ b/frontend/app/search/page.tsx @@ -3,6 +3,7 @@ import { useSearchParams } from "next/navigation"; import { Suspense, useMemo } from "react"; +import { Form, SubmitButton, TextField } from "@olinfo/react-components"; import MiniSearch from "minisearch"; import useSWR from "swr"; @@ -13,7 +14,19 @@ import { SearchCard } from "./search"; export default function Page() { return ( <> -

    Risultati ricerca

    +

    Risultati ricerca

    +

    Ricerca

    +
    + +
    + Puoi cercare un partecipante, un problema o una gara +
    + Cerca + }> @@ -21,6 +34,10 @@ export default function Page() { ); } +function searchAction({ q }: { q: string }) { + window.history.pushState({}, "", `/search?q=${q}`); +} + function PageInner() { const params = useSearchParams(); @@ -28,14 +45,23 @@ function PageInner() { revalidateIfStale: false, revalidateOnFocus: false, }); + + const query = params.get("q") ?? ""; const results = useMemo( - () => search?.search(params.get("q") ?? "", { prefix: true, fuzzy: true }).slice(0, 20), - [search, params], + () => search?.search(query, { prefix: true, fuzzy: true }).slice(0, 20), + [search, query], ); + if (!query) { + return ( +
    + Usa la barra di ricerca per trovare un partecipante, un problema o una gara +
    + ); + } if (!results) return ; if (results.length === 0) { - return
    Nessun risultato trovato
    ; + return
    Nessun risultato trovato
    ; } return ( diff --git a/frontend/components/search.tsx b/frontend/components/search.tsx index dc35838c14..cf2401fb51 100644 --- a/frontend/components/search.tsx +++ b/frontend/components/search.tsx @@ -1,5 +1,6 @@ "use client"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { FormEvent } from "react"; @@ -14,18 +15,23 @@ export function Search() { }; return ( -
    - - +
    + - - + + ); }