diff --git a/src/App.jsx b/src/App.jsx index 0802c0e..44e208c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,15 +1,16 @@ import { useEffect, useRef, useState } from "react"; import { comprobarDuplicado, contienepalabrasProhibidas, enviarPropuesta, obtenerPalabrasFiltradas, suscribirLocales } from "./firebase.js"; import { CATEGORIAS, COLORES_MAPA, NOMBRES_CATEGORIAS, obtenerCategoria } from "./constants/categorias.js"; -import { COORDS_PROVINCIAS, PROVINCIAS, CENTRO_ESPANA } from "./constants/provincias.js"; +import { COORDS_PROVINCIAS, CENTRO_ESPANA } from "./constants/provincias.js"; import { distanciaKm as calcularDistanciaKm, enlaceGoogleMapsDesdeLocal, enlaceWazeDesdeLocal } from "./utils/geo.js"; -import { inputStyle, ANCHO_CUERPO } from "./styles/shared.js"; +import { ANCHO_CUERPO } from "./styles/shared.js"; import LocalCard from "./components/LocalCard.jsx"; import BannerMovil from "./components/BannerMovil.jsx"; import ModalPrivacidad from "./components/ModalPrivacidad.jsx"; import BotonFlotante from "./components/BotonFlotante.jsx"; import BotonProponerArriba from "./components/BotonProponerArriba.jsx"; import ModalPasarela from "./components/ModalPasarela.jsx"; +import BarraFiltros from "./components/BarraFiltros.jsx"; import useFavoritos from "./hooks/useFavoritos.js"; import useUbicacion from "./hooks/useUbicacion.js"; @@ -161,8 +162,6 @@ export default function App() { guardarPropuesta(posibleDuplicado.lat, posibleDuplicado.lng); }; - const subcatsFiltro = filtroCategoria ? CATEGORIAS[filtroCategoria]?.subcategorias || [] : []; - const localesFiltrados = locales .filter((l) => { const q = busqueda.toLowerCase(); @@ -252,7 +251,6 @@ export default function App() { }); } - const conteosCat = NOMBRES_CATEGORIAS.reduce((acc, c) => { acc[c] = locales.filter((l) => l.categoria === c).length; return acc; }, {}); const provincias = [...new Set(locales.map((l) => l.provincia))].sort(); const mediaGlobal = locales.length ? (locales.reduce((s, l) => s + l.puntuacion, 0) / locales.length).toFixed(1) : "—"; @@ -296,22 +294,21 @@ export default function App() { ))} - {/* Chips categorías */} -
- {NOMBRES_CATEGORIAS.map((cat) => { - const c = CATEGORIAS[cat]; - const activo = filtroCategoria === cat; - return ( - - ); - })} - {filtroCategoria && } -
+ {/* Barra de filtros (sección única: chips de categorías y, en vista + lista, búsqueda + selects + acciones rápidas). El estado vive aquí + y se pasa por props; la derivación localesFiltrados es compartida + con el mapa. */} + {/* Tabs */} @@ -326,43 +323,6 @@ export default function App() { {vista === "lista" && ( <> -
- setBusqueda(e.target.value)} aria-label="Buscar por nombre, dirección o categoría" /> - - - -
- -
- {!ubicacion ? ( - - ) : ( - - )} - {errorUbicacion && {errorUbicacion}} - -
- {loading ? (
diff --git a/src/components/BarraFiltros.jsx b/src/components/BarraFiltros.jsx new file mode 100644 index 0000000..3caf129 --- /dev/null +++ b/src/components/BarraFiltros.jsx @@ -0,0 +1,86 @@ +import { CATEGORIAS, NOMBRES_CATEGORIAS } from "../constants/categorias.js"; +import { PROVINCIAS } from "../constants/provincias.js"; +import { inputStyle } from "../styles/shared.js"; + +// UI de filtrado del directorio. El estado vive en App.jsx (la derivación de +// localesFiltrados la comparten lista y mapa); este componente solo pinta y +// dispara los setters recibidos por props. +// Refactor neutro inicial: reproduce los controles que antes vivían en App +// (chips de categorías + grid búsqueda/selects + fila ubicación/favoritos). +export default function BarraFiltros({ + vista, + locales, + favoritos, + busqueda, setBusqueda, + filtroCategoria, setFiltroCategoria, + filtroSubcat, setFiltroSubcat, + filtroProvincia, setFiltroProvincia, + orden, setOrden, + soloFavoritos, setSoloFavoritos, + ubicacion, buscandoUbicacion, errorUbicacion, pedirUbicacion, limpiarUbicacion, +}) { + const conteosCat = NOMBRES_CATEGORIAS.reduce((acc, c) => { acc[c] = locales.filter((l) => l.categoria === c).length; return acc; }, {}); + const subcatsFiltro = filtroCategoria ? CATEGORIAS[filtroCategoria]?.subcategorias || [] : []; + + return ( + <> + {/* Chips categorías */} +
+ {NOMBRES_CATEGORIAS.map((cat) => { + const c = CATEGORIAS[cat]; + const activo = filtroCategoria === cat; + return ( + + ); + })} + {filtroCategoria && } +
+ + {vista === "lista" && ( + <> +
+ setBusqueda(e.target.value)} aria-label="Buscar por nombre, dirección o categoría" /> + + + +
+ +
+ {!ubicacion ? ( + + ) : ( + + )} + {errorUbicacion && {errorUbicacion}} + +
+ + )} + + ); +}