aboutsummaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorAriel Costas Guerrero <94913521+arielcostas@users.noreply.github.com>2024-09-09 18:56:46 +0200
committerAriel Costas Guerrero <94913521+arielcostas@users.noreply.github.com>2024-09-09 18:56:46 +0200
commitf942f8df78a97d302d4ccca8a87e8a410f845dbe (patch)
tree1de4a26cc9ce71f79de054f6b3ec875be487f8bb /src/data
parent9925249bf489ae960189f6daabe59263d1620c89 (diff)
Add recent stop list
Diffstat (limited to 'src/data')
-rw-r--r--src/data/StopDataProvider.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/data/StopDataProvider.ts b/src/data/StopDataProvider.ts
index 620a659..6245e7a 100644
--- a/src/data/StopDataProvider.ts
+++ b/src/data/StopDataProvider.ts
@@ -62,4 +62,30 @@ export class StopDataProvider {
}
return false;
}
+
+ RECENT_STOPS_LIMIT = 10;
+
+ pushRecent(stopId: number) {
+ const rawRecentStops = localStorage.getItem('recentStops');
+ let recentStops: Set<number> = new Set();
+ if (rawRecentStops) {
+ recentStops = new Set(JSON.parse(rawRecentStops) as number[]);
+ }
+
+ recentStops.add(stopId);
+ if (recentStops.size > this.RECENT_STOPS_LIMIT) {
+ const iterator = recentStops.values();
+ recentStops.delete(iterator.next().value);
+ }
+
+ localStorage.setItem('recentStops', JSON.stringify(Array.from(recentStops)));
+ }
+
+ getRecent(): number[] {
+ const rawRecentStops = localStorage.getItem('recentStops');
+ if (rawRecentStops) {
+ return JSON.parse(rawRecentStops) as number[];
+ }
+ return [];
+ }
} \ No newline at end of file