2021-04-15 13:01:58 +01:00
|
|
|
import { Page } from "./types/Page.js";
|
2021-05-07 11:07:03 +01:00
|
|
|
import { allPages } from "./allPages.js"
|
2021-04-15 13:01:58 +01:00
|
|
|
import {
|
|
|
|
getKeyByObjectPropertyValue,
|
|
|
|
} from "./utils.js";
|
|
|
|
|
|
|
|
export class PageState extends Page {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this._currentPage = new Page();
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: When a item in the page state isn't a string (e.g it is a array or object),
|
|
|
|
// you need to add helper methods to mutate it or else it wont save.
|
|
|
|
// example: currentSecretPath is a array so when you try to .push() to it
|
|
|
|
// it will modify the object that was getted from this class
|
|
|
|
// then when you try to access it again, there will be a different object.
|
|
|
|
// I guess you could make another class that emulates a Array or Map
|
|
|
|
// by using a bunch of functions and modifying localStorage in order to remove some of
|
|
|
|
// the clunkyness of this approach, but for now, this works.
|
|
|
|
|
2021-04-30 10:38:23 +01:00
|
|
|
get apiURL() {
|
2021-05-07 11:07:03 +01:00
|
|
|
let apiurl = localStorage.getItem('apiURL') || "";
|
|
|
|
return apiurl.length > 0 ? apiurl : null;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
|
|
|
set apiURL(value) {
|
|
|
|
localStorage.setItem('apiURL', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get token() {
|
2021-05-07 11:07:03 +01:00
|
|
|
let tok = localStorage.getItem('token') || "";
|
|
|
|
return tok.length > 0 ? tok : null;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
|
|
|
set token(value) {
|
|
|
|
localStorage.setItem('token', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get language() {
|
|
|
|
return localStorage.getItem('language') || "";
|
|
|
|
}
|
|
|
|
set language(value) {
|
|
|
|
localStorage.setItem('language', value);
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:01:58 +01:00
|
|
|
get currentBaseMount() {
|
|
|
|
return localStorage.getItem('currentBaseMount') || "";
|
|
|
|
}
|
|
|
|
set currentBaseMount(value) {
|
2021-04-18 10:42:57 +01:00
|
|
|
localStorage.setItem('currentBaseMount', value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Since this is a array we can't act directly on it so we need
|
|
|
|
// functions to do the same modifications.
|
|
|
|
// See the note at the start o
|
|
|
|
popCurrentSecretPath() {
|
|
|
|
let secPath = this.currentSecretPath;
|
|
|
|
secPath.pop();
|
|
|
|
this.currentSecretPath = secPath;
|
|
|
|
}
|
|
|
|
pushCurrentSecretPath(...args) {
|
|
|
|
let secPath = this.currentSecretPath;
|
|
|
|
secPath.push(...args);
|
|
|
|
this.currentSecretPath = secPath;
|
|
|
|
}
|
|
|
|
get currentSecretPath() {
|
|
|
|
return JSON.parse(localStorage.getItem('currentSecretPath') || "[]");
|
|
|
|
}
|
|
|
|
set currentSecretPath(value) {
|
2021-04-18 10:42:57 +01:00
|
|
|
localStorage.setItem('currentSecretPath', JSON.stringify(value));
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get currentSecretVersion() {
|
2021-05-05 17:49:08 +01:00
|
|
|
let result = localStorage.getItem('currentSecretVersion')
|
|
|
|
|
|
|
|
return result != "null" ? result || null : null;
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
set currentSecretVersion(value) {
|
2021-05-05 17:49:08 +01:00
|
|
|
localStorage.setItem('currentSecretVersion', String(value));
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get currentSecret() {
|
|
|
|
return localStorage.getItem('currentSecret') || "";
|
|
|
|
}
|
|
|
|
set currentSecret(value) {
|
2021-04-18 10:42:57 +01:00
|
|
|
localStorage.setItem('currentSecret', value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get currentMountType() {
|
|
|
|
return localStorage.getItem('currentMountType') || "";
|
|
|
|
}
|
|
|
|
set currentMountType(value) {
|
2021-04-18 10:42:57 +01:00
|
|
|
localStorage.setItem('currentMountType', value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
get currentPage() {
|
|
|
|
let curPage = localStorage.getItem('currentPage') || "HOME";
|
2021-05-07 11:07:03 +01:00
|
|
|
return allPages[curPage];
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-04-19 20:17:07 +01:00
|
|
|
get currentPageString() {
|
2021-05-07 11:07:03 +01:00
|
|
|
let key = getKeyByObjectPropertyValue(allPages, this.currentPage);
|
2021-04-19 20:17:07 +01:00
|
|
|
return key;
|
|
|
|
}
|
2021-04-15 13:01:58 +01:00
|
|
|
set currentPage(value) {
|
2021-05-07 11:07:03 +01:00
|
|
|
if (typeof page == 'object') {
|
|
|
|
let key = getKeyByObjectPropertyValue(allPages, value);
|
|
|
|
localStorage.setItem('currentPage', key);
|
|
|
|
} else {
|
|
|
|
localStorage.setItem('currentPage', value);
|
|
|
|
}
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
}
|