aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/data/StopDataProvider.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/data/StopDataProvider.ts')
-rw-r--r--src/frontend/app/data/StopDataProvider.ts37
1 files changed, 29 insertions, 8 deletions
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 {