diff options
| author | Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> | 2024-09-09 18:56:46 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> | 2024-09-09 18:56:46 +0200 |
| commit | f942f8df78a97d302d4ccca8a87e8a410f845dbe (patch) | |
| tree | 1de4a26cc9ce71f79de054f6b3ec875be487f8bb /src/data/StopDataProvider.ts | |
| parent | 9925249bf489ae960189f6daabe59263d1620c89 (diff) | |
Add recent stop list
Diffstat (limited to 'src/data/StopDataProvider.ts')
| -rw-r--r-- | src/data/StopDataProvider.ts | 26 |
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 |
