1
0
Fork 0

Remove PageState rom PageRouter.

This commit is contained in:
Kitteh 2021-05-16 09:42:43 +01:00
parent 1e95a2af87
commit 364679d4e4
4 changed files with 27 additions and 24 deletions

View file

@ -1,5 +1,4 @@
import { PageType } from "./PageType"; import { PageType } from "./PageType";
import { PageState } from "../PageState";
import { getObjectKeys } from "../utils"; import { getObjectKeys } from "../utils";
type pageList = { type pageList = {
@ -12,7 +11,7 @@ const PageHasNotBeenSetError = new Error("Page has not been set.");
export class PageRouter extends EventTarget { export class PageRouter extends EventTarget {
constructor( constructor(
pages: pageList, pages: pageList,
state: PageState, state: unknown,
pageContentElement: HTMLElement, pageContentElement: HTMLElement,
pageTitleElement: HTMLElement, pageTitleElement: HTMLElement,
) { ) {
@ -27,7 +26,7 @@ export class PageRouter extends EventTarget {
private currentPageID: string; private currentPageID: string;
private currentPage: PageType; private currentPage: PageType;
public state: PageState; public state: unknown;
public pageContentElement: HTMLElement; public pageContentElement: HTMLElement;
public pageTitleElement: HTMLElement; public pageTitleElement: HTMLElement;

View file

@ -1,46 +1,48 @@
import { PageRouter } from "../PageSystem/PageRouter"; import { PageRouter } from "../PageSystem/PageRouter";
import { makeElement } from "../htmlUtils"; import { makeElement } from "../htmlUtils";
import { PageState } from "../PageState";
function currentTitleSecretText(router: PageRouter, suffix = ""): string { function currentTitleSecretText(state: PageState, suffix = ""): string {
let currentSecretText = router.state.currentSecret; let currentSecretText = state.currentSecret;
currentSecretText += suffix; currentSecretText += suffix;
if (router.state.currentSecretVersion !== null) if (state.currentSecretVersion !== null)
currentSecretText += ` (v${router.state.currentSecretVersion})`; currentSecretText += ` (v${state.currentSecretVersion})`;
return currentSecretText; return currentSecretText;
} }
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> { export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
let state = router.state as PageState;
const titleElement = makeElement({ const titleElement = makeElement({
tag: "div", tag: "div",
children: [ children: [
makeElement({ makeElement({
tag: "a", tag: "a",
text: router.state.currentBaseMount + " ", text: state.currentBaseMount + " ",
onclick: async () => { onclick: async () => {
router.state.currentSecretPath = []; state.currentSecretPath = [];
router.state.currentSecret = ""; state.currentSecret = "";
router.state.currentSecretVersion = null; state.currentSecretVersion = null;
if ( if (
router.state.currentMountType.startsWith("kv") || state.currentMountType.startsWith("kv") ||
router.state.currentMountType == "cubbyhole" state.currentMountType == "cubbyhole"
) { ) {
await router.changePage("KEY_VALUE_VIEW"); await router.changePage("KEY_VALUE_VIEW");
} else if (router.state.currentMountType == "totp") { } else if (state.currentMountType == "totp") {
await router.changePage("TOTP"); await router.changePage("TOTP");
} else if (router.state.currentMountType == "transit") { } else if (state.currentMountType == "transit") {
await router.changePage("TRANSIT_VIEW"); await router.changePage("TRANSIT_VIEW");
} }
}, },
}), }),
...router.state.currentSecretPath.map((secretPath, index, secretPaths) => { ...state.currentSecretPath.map((secretPath, index, secretPaths) => {
return makeElement({ return makeElement({
tag: "a", tag: "a",
text: secretPath + " ", text: secretPath + " ",
onclick: async () => { onclick: async () => {
router.state.currentSecretVersion = null; state.currentSecretVersion = null;
if (router.state.currentMountType.startsWith("kv")) { if (state.currentMountType.startsWith("kv")) {
router.state.currentSecretPath = secretPaths.slice(0, index + 1); state.currentSecretPath = secretPaths.slice(0, index + 1);
await router.changePage("KEY_VALUE_VIEW"); await router.changePage("KEY_VALUE_VIEW");
} }
}, },
@ -48,8 +50,8 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
}), }),
makeElement({ makeElement({
tag: "span", tag: "span",
condition: router.state.currentSecret.length != 0, condition: state.currentSecret.length != 0,
text: currentTitleSecretText(router, suffix), text: currentTitleSecretText(state, suffix),
}), }),
], ],
}); });

View file

@ -4,13 +4,15 @@ import { lookupSelf } from "./api/sys/lookupSelf";
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";
import UIkit from "uikit"; import UIkit from "uikit";
import i18next from "i18next"; import i18next from "i18next";
import { PageState } from "./PageState";
async function prePageChecksReal(router: PageRouter) { async function prePageChecksReal(router: PageRouter) {
if (router.state.language.length == 0) { let state = router.state as PageState;
if (state.language.length == 0) {
await router.changePage("SET_LANGUAGE"); await router.changePage("SET_LANGUAGE");
throw new Error("Language Not Set"); throw new Error("Language Not Set");
} }
if (!router.state.apiURL) { if (!state.apiURL) {
await router.changePage("SET_VAULT_URL"); await router.changePage("SET_VAULT_URL");
throw new Error("Vault URL Not Set"); throw new Error("Vault URL Not Set");
} }

View file

@ -18,7 +18,7 @@ declare global {
// Please empty this function before committing. // Please empty this function before committing.
export async function playground(router: PageRouter): Promise<void> { export async function playground(router: PageRouter): Promise<void> {
console.log("Welcome to Playground!"); console.log("Welcome to Playground!");
window.pageState = router.state; window.pageState = router.state as PageState;
window.i18next = i18next; window.i18next = i18next;
window.router = router; window.router = router;
} }