Files
firefly-iii/resources/assets/v4/store/Basic.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-07-11 11:45:55 +02:00
// basic store for preferred date range and some other vars.
// used in layout.
import Get from '../api/preferences/index.js';
2023-07-11 11:45:55 +02:00
class Basic {
viewRange = '1M';
darkMode = 'browser';
listPageSize = 10;
locale = 'en-US';
language = 'en-US';
2023-07-11 11:45:55 +02:00
currencyCode = 'AAA';
currencyId = '0';
ready = false;
count = 0;
readyCount = 4;
2023-07-11 11:45:55 +02:00
constructor() {
}
init() {
this.loadVariable('viewRange')
this.loadVariable('darkMode')
this.loadVariable('language')
this.loadVariable('locale')
2023-07-11 11:45:55 +02:00
}
loadVariable(name) {
if (window.hasOwnProperty(name)) {
2023-07-11 11:45:55 +02:00
this[name] = window[name];
return;
}
// load from local storage
if (window.Alpine.store(name)) {
2023-07-11 11:45:55 +02:00
this[name] = window.Alpine.store(name);
return;
}
// grab
let getter = (new Get);
getter.getByName(name).then((response) => this.parseResponse(name, response));
}
parseResponse(name, response) {
this.count++;
let value = response.data.data.attributes.data;
this[name] = value;
if (this.count === this.readyCount) {
// trigger event:
const event = new Event("BasicStoreReady");
document.dispatchEvent(event);
}
2023-07-11 11:45:55 +02:00
}
}
export default Basic;