aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/data')
-rw-r--r--src/frontend/app/data/RegionConfig.ts4
-rw-r--r--src/frontend/app/data/StopDataProvider.ts37
2 files changed, 31 insertions, 10 deletions
diff --git a/src/frontend/app/data/RegionConfig.ts b/src/frontend/app/data/RegionConfig.ts
index c3786ba..08d915f 100644
--- a/src/frontend/app/data/RegionConfig.ts
+++ b/src/frontend/app/data/RegionConfig.ts
@@ -26,7 +26,7 @@ export const REGIONS: Record<RegionId, RegionConfig> = {
defaultCenter: [42.229188855975046, -8.72246955783102],
bounds: {
sw: [-8.951059, 42.098923],
- ne: [-8.447748, 42.3496]
+ ne: [-8.447748, 42.3496],
},
textColour: "#e72b37",
defaultZoom: 14,
@@ -41,7 +41,7 @@ export const REGIONS: Record<RegionId, RegionConfig> = {
defaultCenter: [42.8782, -8.5448],
bounds: {
sw: [-8.884454, 42.719102],
- ne: [-8.243814, 43.02205]
+ ne: [-8.243814, 43.02205],
},
textColour: "#6bb238",
defaultZoom: 14,
diff --git a/src/frontend/app/data/StopDataProvider.ts b/src/frontend/app/data/StopDataProvider.ts
index 799dcb5..7725e15 100644
--- a/src/frontend/app/data/StopDataProvider.ts
+++ b/src/frontend/app/data/StopDataProvider.ts
@@ -47,7 +47,10 @@ async function initStops(region: RegionId) {
// load custom names
const rawCustom = localStorage.getItem(`customStopNames_${region}`);
if (rawCustom) {
- customNamesByRegion[region] = JSON.parse(rawCustom) as Record<number, string>;
+ customNamesByRegion[region] = JSON.parse(rawCustom) as Record<
+ number,
+ string
+ >;
} else {
customNamesByRegion[region] = {};
}
@@ -66,7 +69,10 @@ async function getStops(region: RegionId): Promise<Stop[]> {
}
// New: get single stop by id
-async function getStopById(region: RegionId, stopId: number): Promise<Stop | undefined> {
+async function getStopById(
+ region: RegionId,
+ stopId: number,
+): Promise<Stop | undefined> {
await initStops(region);
const stop = stopsMapByRegion[region]?.[stopId];
if (stop) {
@@ -91,13 +97,19 @@ function setCustomName(region: RegionId, stopId: number, label: string) {
customNamesByRegion[region] = {};
}
customNamesByRegion[region][stopId] = label;
- localStorage.setItem(`customStopNames_${region}`, JSON.stringify(customNamesByRegion[region]));
+ localStorage.setItem(
+ `customStopNames_${region}`,
+ JSON.stringify(customNamesByRegion[region]),
+ );
}
function removeCustomName(region: RegionId, stopId: number) {
if (customNamesByRegion[region]) {
delete customNamesByRegion[region][stopId];
- localStorage.setItem(`customStopNames_${region}`, JSON.stringify(customNamesByRegion[region]));
+ localStorage.setItem(
+ `customStopNames_${region}`,
+ JSON.stringify(customNamesByRegion[region]),
+ );
}
}
@@ -115,7 +127,10 @@ function addFavourite(region: RegionId, stopId: number) {
if (!favouriteStops.includes(stopId)) {
favouriteStops.push(stopId);
- localStorage.setItem(`favouriteStops_${region}`, JSON.stringify(favouriteStops));
+ localStorage.setItem(
+ `favouriteStops_${region}`,
+ JSON.stringify(favouriteStops),
+ );
}
}
@@ -127,7 +142,10 @@ function removeFavourite(region: RegionId, stopId: number) {
}
const newFavouriteStops = favouriteStops.filter((id) => id !== stopId);
- localStorage.setItem(`favouriteStops_${region}`, JSON.stringify(newFavouriteStops));
+ localStorage.setItem(
+ `favouriteStops_${region}`,
+ JSON.stringify(newFavouriteStops),
+ );
}
function isFavourite(region: RegionId, stopId: number): boolean {
@@ -155,7 +173,10 @@ function pushRecent(region: RegionId, stopId: number) {
recentStops.delete(val);
}
- localStorage.setItem(`recentStops_${region}`, JSON.stringify(Array.from(recentStops)));
+ localStorage.setItem(
+ `recentStops_${region}`,
+ JSON.stringify(Array.from(recentStops)),
+ );
}
function getRecent(region: RegionId): number[] {
@@ -179,7 +200,7 @@ async function loadStopsFromNetwork(region: RegionId): Promise<Stop[]> {
const regionConfig = getRegionConfig(region);
const response = await fetch(regionConfig.stopsEndpoint);
const stops = (await response.json()) as Stop[];
- return stops.map((stop) => ({ ...stop, favourite: false } as Stop));
+ return stops.map((stop) => ({ ...stop, favourite: false }) as Stop);
}
export default {