Various fixes

This commit is contained in:
James Cole
2023-07-14 06:04:48 +02:00
parent d943a5ae9b
commit ab3dbf9218
4 changed files with 99 additions and 42 deletions

View File

@@ -5,14 +5,18 @@ import Get from '../api/preferences/index.js';
class Basic {
viewRange = '1M';
darkMode = 'browser';
listPageSize = 10;
locale = 'en-US';
language = 'en-US';
locale = 'en-US';
// others, to be used in the future.
listPageSize = 10;
currencyCode = 'AAA';
currencyId = '0';
ready = false;
count = 0;
readyCount = 4;
start = null;
end = null;
constructor() {
}
@@ -27,11 +31,25 @@ class Basic {
loadVariable(name) {
if (window.hasOwnProperty(name)) {
this[name] = window[name];
this.count++;
if (this.count === this.readyCount) {
// trigger event:
const event = new Event("BasicStoreReady");
document.dispatchEvent(event);
}
return;
}
// load from local storage
if (window.Alpine.store(name)) {
this[name] = window.Alpine.store(name);
if (localStorage.getItem(name)) {
this[name] = localStorage.getItem(name);
this.count++;
if (this.count === this.readyCount) {
// trigger event:
const event = new Event("BasicStoreReady");
document.dispatchEvent(event);
}
return;
}
// grab
@@ -43,12 +61,26 @@ class Basic {
this.count++;
let value = response.data.data.attributes.data;
this[name] = value;
localStorage.setItem(name, value);
if (this.count === this.readyCount) {
// trigger event:
const event = new Event("BasicStoreReady");
document.dispatchEvent(event);
}
}
store(name, value) {
this[name] = value;
localStorage.setItem(name, value);
}
getFromLocalStorage(name) {
return localStorage.getItem(name);
}
isReady() {
return this.count === this.readyCount;
}
}
export default Basic;