From 5ced7f916d94e86e9a7ec164bee56f9a8e3a2a3a Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 26 May 2025 10:48:43 +0200 Subject: Replace Azure SWA with custom server --- src/pages/StopList.tsx | 135 ------------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 src/pages/StopList.tsx (limited to 'src/pages/StopList.tsx') diff --git a/src/pages/StopList.tsx b/src/pages/StopList.tsx deleted file mode 100644 index b965456..0000000 --- a/src/pages/StopList.tsx +++ /dev/null @@ -1,135 +0,0 @@ -import { useEffect, useMemo, useRef, useState } from "react"; -import StopDataProvider, { Stop } from "../data/StopDataProvider"; -import StopItem from "../components/StopItem"; -import Fuse from "fuse.js"; - -const placeholders = [ - "Urzaiz", - "Gran Vía", - "Castelao", - "García Barbón", - "Valladares", - "Florida", - "Pizarro", - "Estrada Madrid", - "Sanjurjo Badía" -]; - -export function StopList() { - const [data, setData] = useState(null) - const [searchResults, setSearchResults] = useState(null); - const searchTimeout = useRef(null); - - const randomPlaceholder = useMemo(() => placeholders[Math.floor(Math.random() * placeholders.length)], []); - const fuse = useMemo(() => new Fuse(data || [], { threshold: 0.3, keys: ['name.original'] }), [data]); - - useEffect(() => { - StopDataProvider.getStops().then((stops: Stop[]) => setData(stops)) - }, []); - - const handleStopSearch = (event: React.ChangeEvent) => { - const stopName = event.target.value || ""; - - if (searchTimeout.current) { - clearTimeout(searchTimeout.current); - } - - searchTimeout.current = setTimeout(() => { - if (stopName.length === 0) { - setSearchResults(null); - return; - } - - if (!data) { - console.error("No data available for search"); - return; - } - - const results = fuse.search(stopName); - const items = results.map(result => result.item); - setSearchResults(items); - }, 300); - } - - const favouritedStops = useMemo(() => { - return data?.filter(stop => stop.favourite) ?? [] - }, [data]) - - const recentStops = useMemo(() => { - // no recent items if data not loaded - if (!data) return null; - const recentIds = StopDataProvider.getRecent(); - if (recentIds.length === 0) return null; - // map and filter out missing entries - const stopsList = recentIds - .map(id => data.find(stop => stop.stopId === id)) - .filter((s): s is Stop => Boolean(s)); - return stopsList.reverse(); - }, [data]); - - if (data === null) return

Loading...

- - return ( -
-

UrbanoVigo Web

- -
-
- - -
-
- - {searchResults && searchResults.length > 0 && ( -
-

Resultados de la búsqueda

-
    - {searchResults.map((stop: Stop) => ( - - ))} -
-
- )} - -
-

Paradas favoritas

- - {favouritedStops?.length === 0 && ( -

- Accede a una parada y márcala como favorita para verla aquí. -

- )} - -
    - {favouritedStops?.sort((a, b) => a.stopId - b.stopId).map((stop: Stop) => ( - - ))} -
-
- - {recentStops && recentStops.length > 0 && ( -
-

Recientes

- -
    - {recentStops.map((stop: Stop) => ( - - ))} -
-
- )} - -
-

Paradas

- -
    - {data?.sort((a, b) => a.stopId - b.stopId).map((stop: Stop) => ( - - ))} -
-
-
- ) -} -- cgit v1.3