51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
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;
|
|
}
|