2022-10-30 13:40:24 +01:00
|
|
|
import Log from "./Log.js";
|
|
|
|
|
|
|
|
export default class LocationStorage {
|
|
|
|
|
|
|
|
static KEY = 'midefos-idealista-location-storage';
|
|
|
|
|
|
|
|
static get storage() {
|
|
|
|
return window.localStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get data() {
|
|
|
|
if (!this._data) {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
return JSON.parse(this._data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get _data() {
|
2023-02-25 12:04:00 +01:00
|
|
|
return this.storage.getItem(this.KEY);
|
2022-10-30 13:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static get(name) {
|
|
|
|
const locations = this.data;
|
|
|
|
return locations[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
static save(location) {
|
|
|
|
const locations = this.data;
|
|
|
|
locations[location.name] = location;
|
|
|
|
this._save(locations);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _init() {
|
|
|
|
Log.debug(`Init location storage`);
|
|
|
|
this._save({});
|
|
|
|
}
|
|
|
|
|
|
|
|
static _save(data) {
|
|
|
|
const json = JSON.stringify(data);
|
2023-02-25 12:04:00 +01:00
|
|
|
this.storage.setItem(this.KEY, json);
|
2022-10-30 13:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|