diff options
Diffstat (limited to 'src/frontend/app/data')
| -rw-r--r-- | src/frontend/app/data/LineColors.ts | 5 | ||||
| -rw-r--r-- | src/frontend/app/data/LinesData.ts | 472 | ||||
| -rw-r--r-- | src/frontend/app/data/StopDataProvider.ts | 63 |
3 files changed, 275 insertions, 265 deletions
diff --git a/src/frontend/app/data/LineColors.ts b/src/frontend/app/data/LineColors.ts index 4e5fe8f..d24d870 100644 --- a/src/frontend/app/data/LineColors.ts +++ b/src/frontend/app/data/LineColors.ts @@ -1,4 +1,3 @@ - interface LineColorInfo { background: string; text: string; @@ -61,7 +60,5 @@ export function getLineColour(line: string): LineColorInfo { let formattedLine = /^[a-zA-Z]/.test(line) ? line : `L${line}`; formattedLine = formattedLine.toLowerCase().trim(); - return ( - vigoLineColors[formattedLine.toLowerCase().trim()] ?? defaultLineColor - ); + return vigoLineColors[formattedLine.toLowerCase().trim()] ?? defaultLineColor; } diff --git a/src/frontend/app/data/LinesData.ts b/src/frontend/app/data/LinesData.ts index 13224e6..cd661b3 100644 --- a/src/frontend/app/data/LinesData.ts +++ b/src/frontend/app/data/LinesData.ts @@ -1,7 +1,7 @@ export interface LineInfo { - lineNumber: string; - routeName: string; - scheduleUrl: string; + lineNumber: string; + routeName: string; + scheduleUrl: string; } /** @@ -17,236 +17,240 @@ export interface LineInfo { */ - export const VIGO_LINES: LineInfo[] = [ - { - "lineNumber": "C1", - "routeName": "P.América - C. Castillo - P.Sanz - G.Via - P.América", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1.pdf" - }, - { - "lineNumber": "C3d", - "routeName": "Bouzas/Coia - E.Fadrique - Encarnación (dereita) - Pza España - Bouzas/Coia", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/3001.pdf" - }, - { - "lineNumber": "C3i", - "routeName": "Bouzas/Coia - Pza España - Encarnación (esquerda) - E.Fadrique - Bouzas/Coia", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/3002.pdf" - }, - { - "lineNumber": "4A", - "routeName": "Coia - Camelias - Centro - Aragón", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/4001.pdf" - }, - { - "lineNumber": "4C", - "routeName": "Coia - Camelias - Centro - M.Garrido - Gregorio Espino", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/4003.pdf" - }, - { - "lineNumber": "5A", - "routeName": "Navia - Florida - L.Mora - Urzaiz - T.Vigo - Teis", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/5001.pdf" - }, - { - "lineNumber": "5B", - "routeName": "Navia - Coia - L.Mora - Pi Margall - G.Barbón - Teis", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/5004.pdf" - }, - { - "lineNumber": "6", - "routeName": "H.Cunqueiro - Beade - Bembrive - Pza. España", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/6.pdf" - }, - { - "lineNumber": "7", - "routeName": "Zamans/Valladares - Fragoso - P.América - P.España - Centro", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/7.pdf" - }, - { - "lineNumber": "9B", - "routeName": "Centro - Choróns - San Cristovo - Rabadeira", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/9002.pdf" - }, - { - "lineNumber": "10", - "routeName": "Teis - G.Barbón - Torrecedeira - Av. Atlántida - Samil - Vao - Saiáns", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/10.pdf" - }, - { - "lineNumber": "11", - "routeName": "San Miguel - Vao - P. América - Urzaiz - Ramón Nieto - Grileira", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/11.pdf" - }, - { - "lineNumber": "12A", - "routeName": "Saiáns - Muiños - Castelao - Pi Margall - P.España - H.Meixoeiro", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1201.pdf" - }, - { - "lineNumber": "12B", - "routeName": "H.Cunqueiro - Castrelos - Camelias - P.España - H.Meixoeiro", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1202.pdf" - }, - { - "lineNumber": "13", - "routeName": "Navia - Bouzas - Gran Vía - P.España - H.Meixoeiro", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/13.pdf" - }, - { - "lineNumber": "14", - "routeName": "Gran Vía - Miraflores - Moledo - Chans", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/14.pdf" - }, - { - "lineNumber": "15A", - "routeName": "Av. Ponte - Choróns - Gran Vía - Castelao - Navia - Samil", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1501.pdf" - }, - { - "lineNumber": "15B", - "routeName": "Xestoso - Choróns - P.Sanz - Beiramar - Bouzas - Samil", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1506.pdf" - }, - { - "lineNumber": "15C", - "routeName": "CUVI - Choróns - P.Sanz - Torrecedeira - Bouzas - Samil", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1507.pdf" - }, - { - "lineNumber": "16", - "routeName": "Coia - Balaídos - Zamora - P.España - Colón - Guixar", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/16.pdf" - }, - { - "lineNumber": "17", - "routeName": "Matamá/Freixo - Fragoso - Camelias - G.Barbón - Ríos/A Guía", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/17.pdf" - }, - { - "lineNumber": "18A", - "routeName": "AREAL/COLÓN - SÁRDOMA/POULEIRA", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/18.pdf" - }, - { - "lineNumber": "18B", - "routeName": "URZAIZ / P.ESPAÑA - POULEIRA", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1801.pdf" - }, - { - "lineNumber": "18H", - "routeName": "URZAIZ / P. ESPAÑA - H. ALV. CUNQUEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/1802.pdf" - }, - { - "lineNumber": "23", - "routeName": "M. ECHEGARAY - Balaídos - Gran Vía - Choróns - Gregorio Espino", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/23.pdf" - }, - { - "lineNumber": "24", - "routeName": "Poulo - Vía Norte - Colón - Guixar", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/24.pdf" - }, - { - "lineNumber": "25", - "routeName": "PZA. ESPAÑA – SABAXÁNS / CAEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/25.pdf" - }, - { - "lineNumber": "27", - "routeName": "BEADE (C. CULTURAL) – RABADEIRA", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/27.pdf" - }, - { - "lineNumber": "28", - "routeName": "VIGOZOO - SAN PAIO - BOUZAS", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/28.pdf" - }, - { - "lineNumber": "29", - "routeName": "FRAGOSELO / S. ANDRÉS – PZA. ESPAÑA", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/29.pdf" - }, - { - "lineNumber": "31", - "routeName": "SAN LOURENZO – HOSP. MEIXOEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/31.pdf" - }, - { - "lineNumber": "A", - "routeName": "ARENAL – PORTO / UNIVERSIDADE", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/8.pdf" - }, - { - "lineNumber": "H", - "routeName": "NAVIA - BOUZAS - HOSPITAL ALVARO CUNQUEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/104.pdf" - }, - { - "lineNumber": "H1", - "routeName": "POLICARPO SANZ – HOSPITAL ÁLVARO CUNQUEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/101.pdf" - }, - { - "lineNumber": "H2", - "routeName": "GREGORIO ESPINO – HOSPITAL ÁLVARO CUNQU", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/102.pdf" - }, - { - "lineNumber": "H3", - "routeName": "GARCÍA BARBÓN – HOSPITAL ÁLVARO CUNQUEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/105.pdf" - }, - { - "lineNumber": "LZD", - "routeName": "STELLANTIS - ALV. CUNQUEIRO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/751.pdf" - }, - { - "lineNumber": "N1", - "routeName": "SAMIL – BUENOS AIRES", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/30.pdf" - }, - { - "lineNumber": "N4", - "routeName": "NAVIA - G. ESPINO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/3305.pdf" - }, - { - "lineNumber": "PSA1", - "routeName": "STELLANTIS - G.BARBON", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/301.pdf" - }, - { - "lineNumber": "PSA4", - "routeName": "STELLANTIS - G. BARBON", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/4004.pdf" - }, - { - "lineNumber": "PTL", - "routeName": "PARQUE TECNOLÓXICO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/304.pdf" - }, - { - "lineNumber": "TUR", - "routeName": "TURISTICO", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/500.pdf" - }, - { - "lineNumber": "U1", - "routeName": "LANZADEIRA PZA. AMÉRICA – UNIVERSIDADE", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/201.pdf" - }, - { - "lineNumber": "U2", - "routeName": "LANZADEIRA PZA. DE ESPAÑA – UNIVERSIDADE", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/202.pdf" - }, - { - "lineNumber": "VTS", - "routeName": "CABRAL - BASE", - "scheduleUrl": "https://vitrasa.es/documents/5893389/6130928/3010.pdf" - } + { + lineNumber: "C1", + routeName: "P.América - C. Castillo - P.Sanz - G.Via - P.América", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1.pdf", + }, + { + lineNumber: "C3d", + routeName: + "Bouzas/Coia - E.Fadrique - Encarnación (dereita) - Pza España - Bouzas/Coia", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/3001.pdf", + }, + { + lineNumber: "C3i", + routeName: + "Bouzas/Coia - Pza España - Encarnación (esquerda) - E.Fadrique - Bouzas/Coia", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/3002.pdf", + }, + { + lineNumber: "4A", + routeName: "Coia - Camelias - Centro - Aragón", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/4001.pdf", + }, + { + lineNumber: "4C", + routeName: "Coia - Camelias - Centro - M.Garrido - Gregorio Espino", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/4003.pdf", + }, + { + lineNumber: "5A", + routeName: "Navia - Florida - L.Mora - Urzaiz - T.Vigo - Teis", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/5001.pdf", + }, + { + lineNumber: "5B", + routeName: "Navia - Coia - L.Mora - Pi Margall - G.Barbón - Teis", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/5004.pdf", + }, + { + lineNumber: "6", + routeName: "H.Cunqueiro - Beade - Bembrive - Pza. España", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/6.pdf", + }, + { + lineNumber: "7", + routeName: "Zamans/Valladares - Fragoso - P.América - P.España - Centro", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/7.pdf", + }, + { + lineNumber: "9B", + routeName: "Centro - Choróns - San Cristovo - Rabadeira", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/9002.pdf", + }, + { + lineNumber: "10", + routeName: + "Teis - G.Barbón - Torrecedeira - Av. Atlántida - Samil - Vao - Saiáns", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/10.pdf", + }, + { + lineNumber: "11", + routeName: + "San Miguel - Vao - P. América - Urzaiz - Ramón Nieto - Grileira", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/11.pdf", + }, + { + lineNumber: "12A", + routeName: + "Saiáns - Muiños - Castelao - Pi Margall - P.España - H.Meixoeiro", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1201.pdf", + }, + { + lineNumber: "12B", + routeName: "H.Cunqueiro - Castrelos - Camelias - P.España - H.Meixoeiro", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1202.pdf", + }, + { + lineNumber: "13", + routeName: "Navia - Bouzas - Gran Vía - P.España - H.Meixoeiro", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/13.pdf", + }, + { + lineNumber: "14", + routeName: "Gran Vía - Miraflores - Moledo - Chans", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/14.pdf", + }, + { + lineNumber: "15A", + routeName: "Av. Ponte - Choróns - Gran Vía - Castelao - Navia - Samil", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1501.pdf", + }, + { + lineNumber: "15B", + routeName: "Xestoso - Choróns - P.Sanz - Beiramar - Bouzas - Samil", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1506.pdf", + }, + { + lineNumber: "15C", + routeName: "CUVI - Choróns - P.Sanz - Torrecedeira - Bouzas - Samil", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1507.pdf", + }, + { + lineNumber: "16", + routeName: "Coia - Balaídos - Zamora - P.España - Colón - Guixar", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/16.pdf", + }, + { + lineNumber: "17", + routeName: "Matamá/Freixo - Fragoso - Camelias - G.Barbón - Ríos/A Guía", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/17.pdf", + }, + { + lineNumber: "18A", + routeName: "AREAL/COLÓN - SÁRDOMA/POULEIRA", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/18.pdf", + }, + { + lineNumber: "18B", + routeName: "URZAIZ / P.ESPAÑA - POULEIRA", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1801.pdf", + }, + { + lineNumber: "18H", + routeName: "URZAIZ / P. ESPAÑA - H. ALV. CUNQUEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/1802.pdf", + }, + { + lineNumber: "23", + routeName: "M. ECHEGARAY - Balaídos - Gran Vía - Choróns - Gregorio Espino", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/23.pdf", + }, + { + lineNumber: "24", + routeName: "Poulo - Vía Norte - Colón - Guixar", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/24.pdf", + }, + { + lineNumber: "25", + routeName: "PZA. ESPAÑA – SABAXÁNS / CAEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/25.pdf", + }, + { + lineNumber: "27", + routeName: "BEADE (C. CULTURAL) – RABADEIRA", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/27.pdf", + }, + { + lineNumber: "28", + routeName: "VIGOZOO - SAN PAIO - BOUZAS", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/28.pdf", + }, + { + lineNumber: "29", + routeName: "FRAGOSELO / S. ANDRÉS – PZA. ESPAÑA", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/29.pdf", + }, + { + lineNumber: "31", + routeName: "SAN LOURENZO – HOSP. MEIXOEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/31.pdf", + }, + { + lineNumber: "A", + routeName: "ARENAL – PORTO / UNIVERSIDADE", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/8.pdf", + }, + { + lineNumber: "H", + routeName: "NAVIA - BOUZAS - HOSPITAL ALVARO CUNQUEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/104.pdf", + }, + { + lineNumber: "H1", + routeName: "POLICARPO SANZ – HOSPITAL ÁLVARO CUNQUEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/101.pdf", + }, + { + lineNumber: "H2", + routeName: "GREGORIO ESPINO – HOSPITAL ÁLVARO CUNQU", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/102.pdf", + }, + { + lineNumber: "H3", + routeName: "GARCÍA BARBÓN – HOSPITAL ÁLVARO CUNQUEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/105.pdf", + }, + { + lineNumber: "LZD", + routeName: "STELLANTIS - ALV. CUNQUEIRO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/751.pdf", + }, + { + lineNumber: "N1", + routeName: "SAMIL – BUENOS AIRES", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/30.pdf", + }, + { + lineNumber: "N4", + routeName: "NAVIA - G. ESPINO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/3305.pdf", + }, + { + lineNumber: "PSA1", + routeName: "STELLANTIS - G.BARBON", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/301.pdf", + }, + { + lineNumber: "PSA4", + routeName: "STELLANTIS - G. BARBON", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/4004.pdf", + }, + { + lineNumber: "PTL", + routeName: "PARQUE TECNOLÓXICO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/304.pdf", + }, + { + lineNumber: "TUR", + routeName: "TURISTICO", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/500.pdf", + }, + { + lineNumber: "U1", + routeName: "LANZADEIRA PZA. AMÉRICA – UNIVERSIDADE", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/201.pdf", + }, + { + lineNumber: "U2", + routeName: "LANZADEIRA PZA. DE ESPAÑA – UNIVERSIDADE", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/202.pdf", + }, + { + lineNumber: "VTS", + routeName: "CABRAL - BASE", + scheduleUrl: "https://vitrasa.es/documents/5893389/6130928/3010.pdf", + }, ]; diff --git a/src/frontend/app/data/StopDataProvider.ts b/src/frontend/app/data/StopDataProvider.ts index 920c7e1..e523bd1 100644 --- a/src/frontend/app/data/StopDataProvider.ts +++ b/src/frontend/app/data/StopDataProvider.ts @@ -12,7 +12,7 @@ export type StopName = { export interface Stop { stopId: string; - type?: 'bus' | 'train'; + type?: "bus" | "train"; name: StopName; latitude?: number; longitude?: number; @@ -35,7 +35,7 @@ const customNamesByRegion: Record<string, Record<string, string>> = {}; // Helper to normalize ID function normalizeId(id: number | string): string { const s = String(id); - if (s.includes(':')) return s; + if (s.includes(":")) return s; return `vitrasa:${s}`; } @@ -52,8 +52,8 @@ async function initStops() { const entry = { ...raw, stopId: id, - type: raw.type || (id.startsWith('renfe:') ? 'train' : 'bus'), - favourite: false + type: raw.type || (id.startsWith("renfe:") ? "train" : "bus"), + favourite: false, } as Stop; stopsMapByRegion[REGION_DATA.id][id] = entry; return entry; @@ -65,7 +65,7 @@ async function initStops() { const parsed = JSON.parse(rawCustom); const normalized: Record<string, string> = {}; for (const [key, value] of Object.entries(parsed)) { - normalized[normalizeId(key)] = value as string; + normalized[normalizeId(key)] = value as string; } customNamesByRegion[REGION_DATA.id] = normalized; } else { @@ -78,7 +78,9 @@ async function getStops(): Promise<Stop[]> { await initStops(); // update favourites const rawFav = localStorage.getItem("favouriteStops_vigo"); - const favouriteStops = rawFav ? (JSON.parse(rawFav) as (number|string)[]).map(normalizeId) : []; + const favouriteStops = rawFav + ? (JSON.parse(rawFav) as (number | string)[]).map(normalizeId) + : []; cachedStopsByRegion["vigo"]!.forEach( (stop) => (stop.favourite = favouriteStops.includes(stop.stopId)) @@ -87,15 +89,15 @@ async function getStops(): Promise<Stop[]> { } // New: get single stop by id -async function getStopById( - stopId: string | number -): Promise<Stop | undefined> { +async function getStopById(stopId: string | number): Promise<Stop | undefined> { await initStops(); const id = normalizeId(stopId); const stop = stopsMapByRegion[REGION_DATA.id]?.[id]; if (stop) { const rawFav = localStorage.getItem(`favouriteStops_${REGION_DATA.id}`); - const favouriteStops = rawFav ? (JSON.parse(rawFav) as (number|string)[]).map(normalizeId) : []; + const favouriteStops = rawFav + ? (JSON.parse(rawFav) as (number | string)[]).map(normalizeId) + : []; stop.favourite = favouriteStops.includes(id); } return stop; @@ -144,15 +146,14 @@ function addFavourite(stopId: string | number) { const rawFavouriteStops = localStorage.getItem(`favouriteStops_vigo`); let favouriteStops: string[] = []; if (rawFavouriteStops) { - favouriteStops = (JSON.parse(rawFavouriteStops) as (number|string)[]).map(normalizeId); + favouriteStops = (JSON.parse(rawFavouriteStops) as (number | string)[]).map( + normalizeId + ); } if (!favouriteStops.includes(id)) { favouriteStops.push(id); - localStorage.setItem( - `favouriteStops_vigo`, - JSON.stringify(favouriteStops) - ); + localStorage.setItem(`favouriteStops_vigo`, JSON.stringify(favouriteStops)); } } @@ -161,7 +162,9 @@ function removeFavourite(stopId: string | number) { const rawFavouriteStops = localStorage.getItem(`favouriteStops_vigo`); let favouriteStops: string[] = []; if (rawFavouriteStops) { - favouriteStops = (JSON.parse(rawFavouriteStops) as (number|string)[]).map(normalizeId); + favouriteStops = (JSON.parse(rawFavouriteStops) as (number | string)[]).map( + normalizeId + ); } const newFavouriteStops = favouriteStops.filter((sid) => sid !== id); @@ -175,7 +178,9 @@ function isFavourite(stopId: string | number): boolean { const id = normalizeId(stopId); const rawFavouriteStops = localStorage.getItem(`favouriteStops_vigo`); if (rawFavouriteStops) { - const favouriteStops = (JSON.parse(rawFavouriteStops) as (number|string)[]).map(normalizeId); + const favouriteStops = ( + JSON.parse(rawFavouriteStops) as (number | string)[] + ).map(normalizeId); return favouriteStops.includes(id); } return false; @@ -188,7 +193,9 @@ function pushRecent(stopId: string | number) { const rawRecentStops = localStorage.getItem(`recentStops_vigo`); let recentStops: Set<string> = new Set(); if (rawRecentStops) { - recentStops = new Set((JSON.parse(rawRecentStops) as (number|string)[]).map(normalizeId)); + recentStops = new Set( + (JSON.parse(rawRecentStops) as (number | string)[]).map(normalizeId) + ); } recentStops.add(id); @@ -207,7 +214,7 @@ function pushRecent(stopId: string | number) { function getRecent(): string[] { const rawRecentStops = localStorage.getItem(`recentStops_vigo`); if (rawRecentStops) { - return (JSON.parse(rawRecentStops) as (number|string)[]).map(normalizeId); + return (JSON.parse(rawRecentStops) as (number | string)[]).map(normalizeId); } return []; } @@ -215,7 +222,9 @@ function getRecent(): string[] { function getFavouriteIds(): string[] { const rawFavouriteStops = localStorage.getItem(`favouriteStops_vigo`); if (rawFavouriteStops) { - return (JSON.parse(rawFavouriteStops) as (number|string)[]).map(normalizeId); + return (JSON.parse(rawFavouriteStops) as (number | string)[]).map( + normalizeId + ); } return []; } @@ -225,13 +234,13 @@ async function loadStopsFromNetwork(): Promise<Stop[]> { const response = await fetch(REGION_DATA.stopsEndpoint); const rawStops = (await response.json()) as any[]; return rawStops.map((raw) => { - const id = normalizeId(raw.stopId); - return { - ...raw, - stopId: id, - type: raw.type || (id.startsWith('renfe:') ? 'train' : 'bus'), - favourite: false - } as Stop; + const id = normalizeId(raw.stopId); + return { + ...raw, + stopId: id, + type: raw.type || (id.startsWith("renfe:") ? "train" : "bus"), + favourite: false, + } as Stop; }); } |
