1
0
Fork 0

Lint code.

This commit is contained in:
Kitteh 2021-05-16 10:35:35 +01:00
parent 3b251ee46f
commit 2d0733bfc7
5 changed files with 15 additions and 26 deletions

View file

@ -1,7 +1,3 @@
import { Page } from "./types/Page";
import { allPages } from "./allPages";
import { getKeyByObjectPropertyValue } from "./utils";
export class PageState { export class PageState {
constructor() { constructor() {
// Do Nothing // Do Nothing
@ -96,19 +92,13 @@ export class PageState {
localStorage.setItem("currentMountType", value); localStorage.setItem("currentMountType", value);
} }
get currentPageString(): string { get currentPageString(): string {
const key = getKeyByObjectPropertyValue(allPages, this.currentPage); return this.currentPage;
return key;
} }
get currentPage(): Page | string { get currentPage(): string {
const curPage = localStorage.getItem("currentPage") || "HOME"; const curPage = localStorage.getItem("currentPage") || "HOME";
return allPages[curPage]; return curPage;
} }
set currentPage(value: Page | string) { set currentPage(value: string) {
if (typeof value == "object") {
const key = getKeyByObjectPropertyValue(allPages, value);
localStorage.setItem("currentPage", key);
} else {
localStorage.setItem("currentPage", value); localStorage.setItem("currentPage", value);
} }
} }
}

View file

@ -25,7 +25,10 @@ import { TransitViewPage } from "./pages/Transit/TransitView";
import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret"; import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret";
import { UnsealPage } from "./pages/Unseal"; import { UnsealPage } from "./pages/Unseal";
import { getObjectKeys } from "./utils"; import { getObjectKeys } from "./utils";
/* eslint-disable */
import { PageType } from "z-pagerouter"; import { PageType } from "z-pagerouter";
/* eslint-enable */
type pagesList = { type pagesList = {
[key: string]: Page; [key: string]: Page;

View file

@ -1,17 +1,16 @@
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { makeElement } from "../htmlUtils";
import { PageState } from "../PageState"; import { PageState } from "../PageState";
import { makeElement } from "../htmlUtils";
function currentTitleSecretText(state: PageState, suffix = ""): string { function currentTitleSecretText(state: PageState, suffix = ""): string {
let currentSecretText = state.currentSecret; let currentSecretText = state.currentSecret;
currentSecretText += suffix; currentSecretText += suffix;
if (state.currentSecretVersion !== null) if (state.currentSecretVersion !== null) currentSecretText += ` (v${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 state = router.state as PageState;
const titleElement = makeElement({ const titleElement = makeElement({
tag: "div", tag: "div",
children: [ children: [
@ -23,10 +22,7 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
state.currentSecret = ""; state.currentSecret = "";
state.currentSecretVersion = null; state.currentSecretVersion = null;
if ( if (state.currentMountType.startsWith("kv") || state.currentMountType == "cubbyhole") {
state.currentMountType.startsWith("kv") ||
state.currentMountType == "cubbyhole"
) {
await router.changePage("KEY_VALUE_VIEW"); await router.changePage("KEY_VALUE_VIEW");
} else if (state.currentMountType == "totp") { } else if (state.currentMountType == "totp") {
await router.changePage("TOTP"); await router.changePage("TOTP");

View file

@ -21,10 +21,10 @@ Prism.highlightAll();
import { NavBar } from "./elements/NavBar"; import { NavBar } from "./elements/NavBar";
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { pageList } from "./allPages";
import { formatDistance } from "./formatDistance"; import { formatDistance } from "./formatDistance";
import { getSealStatus } from "./api/sys/getSealStatus"; import { getSealStatus } from "./api/sys/getSealStatus";
import { makeElement } from "./htmlUtils"; import { makeElement } from "./htmlUtils";
import { pageList } from "./allPages";
import { pageState } from "./globalPageState"; import { pageState } from "./globalPageState";
import { playground } from "./playground"; import { playground } from "./playground";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,13 +1,13 @@
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { PageState } from "./PageState";
import { getSealStatus } from "./api/sys/getSealStatus"; import { getSealStatus } from "./api/sys/getSealStatus";
import { lookupSelf } from "./api/sys/lookupSelf"; 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) {
let state = router.state as PageState; const state = router.state as PageState;
if (state.language.length == 0) { 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");