From 24253f0cfbdd0c03772f54e74ee3f2798feee3c8 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Tue, 11 Nov 2025 17:15:29 +0100 Subject: [PATCH] feat: refactor Ricerca component layout and enhance filter functionality in DrowdownFilters --- apps/infoalloggi/src/pages/annunci.tsx | 322 +++++++++++++++++-------- 1 file changed, 219 insertions(+), 103 deletions(-) diff --git a/apps/infoalloggi/src/pages/annunci.tsx b/apps/infoalloggi/src/pages/annunci.tsx index 40bc915..b719837 100644 --- a/apps/infoalloggi/src/pages/annunci.tsx +++ b/apps/infoalloggi/src/pages/annunci.tsx @@ -13,7 +13,7 @@ import { } from "lucide-react"; import type { GetServerSideProps } from "next"; import Head from "next/head"; -import { useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { AccordionComp } from "~/components/accordionComp"; import { MapSection } from "~/components/annunci_map"; import { CTA_TipologiaModal } from "~/components/annunci_tutorial"; @@ -125,19 +125,117 @@ const Ricerca = () => { }, [page]); return ( -
- - - {map ? : } +
+ +
+ +
{map ? : }
+
); }; -const RicercaFilters = () => { +const RicercaSideFilters = () => { + const { t } = useTranslation(); + const { + tipo, + setTipo, + comune, + setComune, + consegna, + setConsegna, + sort, + setSort, + comuniOptions, + tipologieOptions, + consegnaOptions, + ResetParams, + nFiltri, + } = useRicerca(); + const mappedConsegnaOptions = useMemo( + // biome-ignore lint/style/noNonNullAssertion: + () => consegnaOptions.map((m) => t.preferenze.mesi[m]!).filter(Boolean), + [consegnaOptions, t.preferenze.mesi], + ); + + return ( +
+ { + await setTipo(""); + }} + label={t.annunci.fs_tipologia.titolo} + onValueChange={async (value: string) => { + await setTipo(value); + }} + options={tipologieOptions} + placeholder={t.seleziona_placeholder} + value={tipo} + /> + { + await setComune(null); + }} + label={t.annunci.comune} + onValueChange={async (value: string) => { + await setComune(value); + }} + options={comuniOptions} + placeholder={t.seleziona_placeholder} + value={comune} + /> + { + await setConsegna(null); + }} + label={t.annunci.consegna} + onValueChange={async (value: string) => { + if (value === "") { + await setConsegna(null); + return; + } + if (t.preferenze.mesi.includes(value)) { + await setConsegna(t.preferenze.mesi.indexOf(value)); + return; + } + console.warn("Value not found in preferenze.mesi"); + await setConsegna(null); + }} + options={mappedConsegnaOptions} + placeholder={t.seleziona_placeholder} + value={consegna ? t.preferenze.mesi[consegna] || "" : ""} + /> + { + await setSort("Recenti"); + }} + label={t.ordina_per} + onValueChange={async (value: SortTypes) => { + await setSort(value); + }} + options={["Recenti", "Prezzo", "Consegna", "Mq"]} + placeholder={t.seleziona_placeholder} + value={sort} + /> + +
+ ); +}; + +const DrowdownFilters = () => { const { t } = useTranslation(); const { - map, - setMap, tipo, setTipo, comune, @@ -160,103 +258,121 @@ const RicercaFilters = () => { [consegnaOptions, t.preferenze.mesi], ); + // Close dropdown when page resizes + const handleResize = useCallback(() => { + setOpen(false); + }, []); + + useEffect(() => { + window.addEventListener("resize", handleResize); + return () => { + window.removeEventListener("resize", handleResize); + }; + }, [handleResize]); + + return ( +
+ + + + + + { + await setTipo(""); + }} + label={t.annunci.fs_tipologia.titolo} + onValueChange={async (value: string) => { + await setTipo(value); + }} + options={tipologieOptions} + placeholder={t.seleziona_placeholder} + value={tipo} + /> + { + await setComune(null); + }} + label={t.annunci.comune} + onValueChange={async (value: string) => { + await setComune(value); + }} + options={comuniOptions} + placeholder={t.seleziona_placeholder} + value={comune} + /> + { + await setConsegna(null); + }} + label={t.annunci.consegna} + onValueChange={async (value: string) => { + if (value === "") { + await setConsegna(null); + return; + } + if (t.preferenze.mesi.includes(value)) { + await setConsegna(t.preferenze.mesi.indexOf(value)); + return; + } + console.warn("Value not found in preferenze.mesi"); + await setConsegna(null); + }} + options={mappedConsegnaOptions} + placeholder={t.seleziona_placeholder} + value={consegna ? t.preferenze.mesi[consegna] || "" : ""} + /> + { + await setSort("Recenti"); + }} + label={t.ordina_per} + onValueChange={async (value: SortTypes) => { + await setSort(value); + }} + options={["Recenti", "Prezzo", "Consegna", "Mq"]} + placeholder={t.seleziona_placeholder} + value={sort} + /> + + + +
+ ); +}; + +const RicercaHeader = () => { + const { map, setMap } = useRicerca(); + return (
-
- - - - - - { - await setTipo(""); - }} - label={t.annunci.fs_tipologia.titolo} - onValueChange={async (value: string) => { - await setTipo(value); - }} - options={tipologieOptions} - placeholder={t.seleziona_placeholder} - value={tipo} - /> - { - await setComune(null); - }} - label={t.annunci.comune} - onValueChange={async (value: string) => { - await setComune(value); - }} - options={comuniOptions} - placeholder={t.seleziona_placeholder} - value={comune} - /> - { - await setConsegna(null); - }} - label={t.annunci.consegna} - onValueChange={async (value: string) => { - if (value === "") { - await setConsegna(null); - return; - } - if (t.preferenze.mesi.includes(value)) { - await setConsegna(t.preferenze.mesi.indexOf(value)); - return; - } - console.warn("Value not found in preferenze.mesi"); - await setConsegna(null); - }} - options={mappedConsegnaOptions} - placeholder={t.seleziona_placeholder} - value={consegna ? t.preferenze.mesi[consegna] || "" : ""} - /> - { - await setSort("Recenti"); - }} - label={t.ordina_per} - onValueChange={async (value: SortTypes) => { - await setSort(value); - }} - options={["Recenti", "Prezzo", "Consegna", "Mq"]} - placeholder={t.seleziona_placeholder} - value={sort} - /> - - - -
+
- +
); };