2021-05-07 23:08:02 +01:00
|
|
|
export class PageState {
|
2021-04-15 13:01:58 +01:00
|
|
|
constructor() {
|
2021-05-07 23:08:02 +01:00
|
|
|
// Do Nothing
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2021-05-12 16:01:04 +01:00
|
|
|
// I guess you could make another class that emulates a Array or Map
|
2021-04-15 13:01:58 +01:00
|
|
|
// 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-05-07 23:08:02 +01:00
|
|
|
get apiURL(): string | null {
|
2021-05-12 16:01:04 +01:00
|
|
|
const apiurl = localStorage.getItem("apiURL") || "";
|
2021-05-07 11:07:03 +01:00
|
|
|
return apiurl.length > 0 ? apiurl : null;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set apiURL(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("apiURL", value);
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
|
|
|
|
get token(): string | null {
|
2021-05-12 16:01:04 +01:00
|
|
|
const tok = localStorage.getItem("token") || "";
|
2021-05-07 11:07:03 +01:00
|
|
|
return tok.length > 0 ? tok : null;
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set token(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("token", value);
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get pageDirection(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
return localStorage.getItem("pageDirection") || "ltr";
|
2021-05-07 20:41:40 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set pageDirection(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("pageDirection", value);
|
2021-05-07 20:41:40 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get language(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
return localStorage.getItem("language") || "";
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set language(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("language", value);
|
2021-04-30 10:38:23 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get currentBaseMount(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
return localStorage.getItem("currentBaseMount") || "";
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set currentBaseMount(value: string) {
|
2021-05-12 16:01:04 +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
|
2021-05-07 23:08:02 +01:00
|
|
|
popCurrentSecretPath(): void {
|
|
|
|
const secPath = this.currentSecretPath;
|
2021-04-15 13:01:58 +01:00
|
|
|
secPath.pop();
|
|
|
|
this.currentSecretPath = secPath;
|
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
pushCurrentSecretPath(...args: string[]): void {
|
|
|
|
const secPath = this.currentSecretPath;
|
2021-04-15 13:01:58 +01:00
|
|
|
secPath.push(...args);
|
|
|
|
this.currentSecretPath = secPath;
|
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
|
|
|
|
get currentSecretPath(): string[] {
|
2021-05-12 16:01:04 +01:00
|
|
|
return JSON.parse(localStorage.getItem("currentSecretPath") || "[]") as string[];
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set currentSecretPath(value: string[]) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("currentSecretPath", JSON.stringify(value));
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get currentSecretVersion(): string | null {
|
2021-05-12 16:01:04 +01:00
|
|
|
const result = localStorage.getItem("currentSecretVersion");
|
2021-05-05 17:49:08 +01:00
|
|
|
return result != "null" ? result || null : null;
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set currentSecretVersion(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("currentSecretVersion", String(value));
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get currentSecret(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
return localStorage.getItem("currentSecret") || "";
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set currentSecret(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("currentSecret", value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
get currentMountType(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
return localStorage.getItem("currentMountType") || "";
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
set currentMountType(value: string) {
|
2021-05-12 16:01:04 +01:00
|
|
|
localStorage.setItem("currentMountType", value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-07 23:08:02 +01:00
|
|
|
get currentPageString(): string {
|
2021-05-16 10:35:35 +01:00
|
|
|
return this.currentPage;
|
2021-04-19 20:17:07 +01:00
|
|
|
}
|
2021-05-16 10:35:35 +01:00
|
|
|
get currentPage(): string {
|
2021-05-12 16:01:04 +01:00
|
|
|
const curPage = localStorage.getItem("currentPage") || "HOME";
|
2021-05-16 10:35:35 +01:00
|
|
|
return curPage;
|
|
|
|
}
|
|
|
|
set currentPage(value: string) {
|
|
|
|
localStorage.setItem("currentPage", value);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
2021-05-12 16:01:04 +01:00
|
|
|
}
|