Remember last used stations
This commit is contained in:
50
web/datastore.js
Normal file
50
web/datastore.js
Normal file
@@ -0,0 +1,50 @@
|
||||
export class LocationsDataStore {
|
||||
static rememberAll(location_list) {
|
||||
let locations = LocationsDataStore.get();
|
||||
for (let location of location_list) {
|
||||
locations[location.id] = location;
|
||||
}
|
||||
LocationsDataStore.set(locations);
|
||||
}
|
||||
|
||||
static get() {
|
||||
return DataStore.get("locations") || {};
|
||||
}
|
||||
|
||||
static set(value) {
|
||||
DataStore.set("locations", value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class RecentLocationsDataStore {
|
||||
static remember(location_id) {
|
||||
let recent_locations = RecentLocationsDataStore.get();
|
||||
recent_locations = recent_locations.filter((item) => {
|
||||
return item != location_id;
|
||||
});
|
||||
recent_locations.push(location_id);
|
||||
RecentLocationsDataStore.set(recent_locations);
|
||||
}
|
||||
|
||||
static get() {
|
||||
return DataStore.get("recent-locations") || [];
|
||||
}
|
||||
|
||||
static set(value) {
|
||||
DataStore.set("recent-locations", value);
|
||||
}
|
||||
}
|
||||
|
||||
export class DataStore {
|
||||
static get(key) {
|
||||
return JSON.parse(window.localStorage.getItem(key));
|
||||
}
|
||||
|
||||
static set(key, value) {
|
||||
window.localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
static locations = LocationsDataStore;
|
||||
static recent_locations = RecentLocationsDataStore;
|
||||
}
|
Reference in New Issue
Block a user