diff --git a/src/PageSystem/PageRouter.ts b/src/PageSystem/PageRouter.ts index 1c73f24..24b3a31 100644 --- a/src/PageSystem/PageRouter.ts +++ b/src/PageSystem/PageRouter.ts @@ -1,5 +1,4 @@ import { PageType } from "./PageType"; -import { PageState } from "../PageState"; import { getObjectKeys } from "../utils"; type pageList = { @@ -12,7 +11,7 @@ const PageHasNotBeenSetError = new Error("Page has not been set."); export class PageRouter extends EventTarget { constructor( pages: pageList, - state: PageState, + state: unknown, pageContentElement: HTMLElement, pageTitleElement: HTMLElement, ) { @@ -27,7 +26,7 @@ export class PageRouter extends EventTarget { private currentPageID: string; private currentPage: PageType; - public state: PageState; + public state: unknown; public pageContentElement: HTMLElement; public pageTitleElement: HTMLElement; diff --git a/src/elements/SecretTitleElement.ts b/src/elements/SecretTitleElement.ts index d827a37..502bf0f 100644 --- a/src/elements/SecretTitleElement.ts +++ b/src/elements/SecretTitleElement.ts @@ -1,46 +1,48 @@ import { PageRouter } from "../PageSystem/PageRouter"; import { makeElement } from "../htmlUtils"; +import { PageState } from "../PageState"; -function currentTitleSecretText(router: PageRouter, suffix = ""): string { - let currentSecretText = router.state.currentSecret; +function currentTitleSecretText(state: PageState, suffix = ""): string { + let currentSecretText = state.currentSecret; currentSecretText += suffix; - if (router.state.currentSecretVersion !== null) - currentSecretText += ` (v${router.state.currentSecretVersion})`; + if (state.currentSecretVersion !== null) + currentSecretText += ` (v${state.currentSecretVersion})`; return currentSecretText; } export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise { + let state = router.state as PageState; const titleElement = makeElement({ tag: "div", children: [ makeElement({ tag: "a", - text: router.state.currentBaseMount + " ", + text: state.currentBaseMount + " ", onclick: async () => { - router.state.currentSecretPath = []; - router.state.currentSecret = ""; - router.state.currentSecretVersion = null; + state.currentSecretPath = []; + state.currentSecret = ""; + state.currentSecretVersion = null; if ( - router.state.currentMountType.startsWith("kv") || - router.state.currentMountType == "cubbyhole" + state.currentMountType.startsWith("kv") || + state.currentMountType == "cubbyhole" ) { await router.changePage("KEY_VALUE_VIEW"); - } else if (router.state.currentMountType == "totp") { + } else if (state.currentMountType == "totp") { await router.changePage("TOTP"); - } else if (router.state.currentMountType == "transit") { + } else if (state.currentMountType == "transit") { await router.changePage("TRANSIT_VIEW"); } }, }), - ...router.state.currentSecretPath.map((secretPath, index, secretPaths) => { + ...state.currentSecretPath.map((secretPath, index, secretPaths) => { return makeElement({ tag: "a", text: secretPath + " ", onclick: async () => { - router.state.currentSecretVersion = null; - if (router.state.currentMountType.startsWith("kv")) { - router.state.currentSecretPath = secretPaths.slice(0, index + 1); + state.currentSecretVersion = null; + if (state.currentMountType.startsWith("kv")) { + state.currentSecretPath = secretPaths.slice(0, index + 1); await router.changePage("KEY_VALUE_VIEW"); } }, @@ -48,8 +50,8 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi }), makeElement({ tag: "span", - condition: router.state.currentSecret.length != 0, - text: currentTitleSecretText(router, suffix), + condition: state.currentSecret.length != 0, + text: currentTitleSecretText(state, suffix), }), ], }); diff --git a/src/pageUtils.ts b/src/pageUtils.ts index 174900b..6fe94ab 100644 --- a/src/pageUtils.ts +++ b/src/pageUtils.ts @@ -4,13 +4,15 @@ import { lookupSelf } from "./api/sys/lookupSelf"; import ClipboardJS from "clipboard"; import UIkit from "uikit"; import i18next from "i18next"; +import { PageState } from "./PageState"; 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"); throw new Error("Language Not Set"); } - if (!router.state.apiURL) { + if (!state.apiURL) { await router.changePage("SET_VAULT_URL"); throw new Error("Vault URL Not Set"); } diff --git a/src/playground.ts b/src/playground.ts index bfbc6ed..c9bd175 100644 --- a/src/playground.ts +++ b/src/playground.ts @@ -18,7 +18,7 @@ declare global { // Please empty this function before committing. export async function playground(router: PageRouter): Promise { console.log("Welcome to Playground!"); - window.pageState = router.state; + window.pageState = router.state as PageState; window.i18next = i18next; window.router = router; }