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 { 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;

View file

@ -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<HTMLElement> {
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),
}),
],
});

View file

@ -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");
}

View file

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