From 4c4a69464fc745ff668665727db9f88aa4b0f53a Mon Sep 17 00:00:00 2001 From: Kitteh Date: Fri, 28 May 2021 12:14:26 +0100 Subject: [PATCH] Change SecretTitleElement props. --- src/pages/Secrets/KeyValue/KeyValueDelete.tsx | 2 +- src/pages/Secrets/KeyValue/KeyValueNew.tsx | 2 +- src/pages/Secrets/KeyValue/KeyValueSecret.tsx | 2 +- .../Secrets/KeyValue/KeyValueSecretsEdit.tsx | 2 +- .../Secrets/KeyValue/KeyValueVersions.tsx | 2 +- src/pages/Secrets/KeyValue/KeyValueView.tsx | 2 +- src/pages/Secrets/SecretTitleElement.tsx | 51 ++++++++++--------- src/pages/Secrets/TOTP/TOTPDelete.tsx | 2 +- src/pages/Secrets/TOTP/TOTPNew.tsx | 2 +- src/pages/Secrets/TOTP/TOTPView.tsx | 2 +- src/pages/Secrets/Transit/NewTransitKey.tsx | 2 +- src/pages/Secrets/Transit/TransitDecrypt.tsx | 2 +- src/pages/Secrets/Transit/TransitEncrypt.tsx | 2 +- src/pages/Secrets/Transit/TransitRewrap.tsx | 2 +- src/pages/Secrets/Transit/TransitView.tsx | 2 +- .../Secrets/Transit/TransitViewSecret.tsx | 2 +- src/state/storage/StorageType.ts | 2 +- 17 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/pages/Secrets/KeyValue/KeyValueDelete.tsx b/src/pages/Secrets/KeyValue/KeyValueDelete.tsx index b09a3c0..6a3c183 100644 --- a/src/pages/Secrets/KeyValue/KeyValueDelete.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueDelete.tsx @@ -43,7 +43,7 @@ export class KeyValueDeletePage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/KeyValue/KeyValueNew.tsx b/src/pages/Secrets/KeyValue/KeyValueNew.tsx index 9eb6e49..75f695a 100644 --- a/src/pages/Secrets/KeyValue/KeyValueNew.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueNew.tsx @@ -63,7 +63,7 @@ export class KeyValueNewPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx index ff6c694..22d70a5 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx @@ -154,7 +154,7 @@ export class KeyValueSecretPage extends Page { } async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + render(, this.router.pageTitleElement); } get name(): string { diff --git a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx index e1a4f0d..dbbc973 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.tsx @@ -117,7 +117,7 @@ export class KeyValueSecretEditPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/KeyValue/KeyValueVersions.tsx b/src/pages/Secrets/KeyValue/KeyValueVersions.tsx index e8e43be..1013788 100644 --- a/src/pages/Secrets/KeyValue/KeyValueVersions.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueVersions.tsx @@ -44,7 +44,7 @@ export class KeyValueVersionsPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/KeyValue/KeyValueView.tsx b/src/pages/Secrets/KeyValue/KeyValueView.tsx index 2d4081d..d7171e3 100644 --- a/src/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueView.tsx @@ -149,7 +149,7 @@ export class KeyValueViewPage extends Page { } async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + render(, this.router.pageTitleElement); } get name(): string { diff --git a/src/pages/Secrets/SecretTitleElement.tsx b/src/pages/Secrets/SecretTitleElement.tsx index 79838e7..99d904b 100644 --- a/src/pages/Secrets/SecretTitleElement.tsx +++ b/src/pages/Secrets/SecretTitleElement.tsx @@ -1,28 +1,26 @@ import { JSX } from "preact/jsx-runtime"; -import { PageRouter } from "z-pagerouter"; -import { PageState } from "../../state/PageState"; +import { Page } from "../../types/Page"; -function currentTitleSecretText(state: PageState): string { - let secretItemText = state.secretItem; - if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`; +function currentTitleSecretText(page: Page): string { + let secretItemText = page.state.secretItem; + if (page.state.secretVersion !== null) secretItemText += ` (v${page.state.secretVersion})`; return secretItemText; } type SecretTitleElementProps = { - router: PageRouter; + page: Page; suffix?: string; }; export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element { - const router = props.router; + const page = props.page; const suffix = props.suffix || ""; - const state = router.state as PageState; return (
{ - await router.changePage("SECRETS_HOME"); + await page.router.changePage("SECRETS_HOME"); }} > {"/ "} @@ -30,35 +28,38 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element { - state.secretPath = []; - state.secretItem = ""; - state.secretVersion = null; + page.state.secretPath = []; + page.state.secretItem = ""; + page.state.secretVersion = null; - if (state.secretMountType.startsWith("kv") || state.secretMountType == "cubbyhole") { - await router.changePage("KEY_VALUE_VIEW"); - } else if (state.secretMountType == "totp") { - await router.changePage("TOTP_VIEW"); - } else if (state.secretMountType == "transit") { - await router.changePage("TRANSIT_VIEW"); + if ( + page.state.secretMountType.startsWith("kv") || + page.state.secretMountType == "cubbyhole" + ) { + await page.router.changePage("KEY_VALUE_VIEW"); + } else if (page.state.secretMountType == "totp") { + await page.router.changePage("TOTP_VIEW"); + } else if (page.state.secretMountType == "transit") { + await page.router.changePage("TRANSIT_VIEW"); } }} > - {state.baseMount + " "} + {page.state.baseMount + " "} - {...state.secretPath.map((secretPath, index, secretPaths) => ( + {...page.state.secretPath.map((secretPath, index, secretPaths) => ( { - state.secretVersion = null; - if (state.secretMountType.startsWith("kv")) { - state.secretPath = secretPaths.slice(0, index + 1); - await router.changePage("KEY_VALUE_VIEW"); + page.state.secretVersion = null; + if (page.state.secretMountType.startsWith("kv")) { + page.state.secretPath = secretPaths.slice(0, index + 1); + await page.router.changePage("KEY_VALUE_VIEW"); } }} > {secretPath + " "} ))} - {state.secretItem.length != 0 && {currentTitleSecretText(state)}} + {page.state.secretItem.length != 0 && {currentTitleSecretText(page)}} {suffix.length != 0 && {suffix}}
); diff --git a/src/pages/Secrets/TOTP/TOTPDelete.tsx b/src/pages/Secrets/TOTP/TOTPDelete.tsx index 6cb83de..50b9afa 100644 --- a/src/pages/Secrets/TOTP/TOTPDelete.tsx +++ b/src/pages/Secrets/TOTP/TOTPDelete.tsx @@ -37,7 +37,7 @@ export class TOTPDeletePage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/TOTP/TOTPNew.tsx b/src/pages/Secrets/TOTP/TOTPNew.tsx index ba4e407..11614e2 100644 --- a/src/pages/Secrets/TOTP/TOTPNew.tsx +++ b/src/pages/Secrets/TOTP/TOTPNew.tsx @@ -131,7 +131,7 @@ export class TOTPNewPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/TOTP/TOTPView.tsx b/src/pages/Secrets/TOTP/TOTPView.tsx index 5845e1f..efc6f50 100644 --- a/src/pages/Secrets/TOTP/TOTPView.tsx +++ b/src/pages/Secrets/TOTP/TOTPView.tsx @@ -120,7 +120,7 @@ export class TOTPViewPage extends Page { } async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + render(, this.router.pageTitleElement); } get name(): string { diff --git a/src/pages/Secrets/Transit/NewTransitKey.tsx b/src/pages/Secrets/Transit/NewTransitKey.tsx index ac243c0..4497e10 100644 --- a/src/pages/Secrets/Transit/NewTransitKey.tsx +++ b/src/pages/Secrets/Transit/NewTransitKey.tsx @@ -78,7 +78,7 @@ export class NewTransitKeyPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/Transit/TransitDecrypt.tsx b/src/pages/Secrets/Transit/TransitDecrypt.tsx index f137b83..3aad7e0 100644 --- a/src/pages/Secrets/Transit/TransitDecrypt.tsx +++ b/src/pages/Secrets/Transit/TransitDecrypt.tsx @@ -84,7 +84,7 @@ export class TransitDecryptPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/Transit/TransitEncrypt.tsx b/src/pages/Secrets/Transit/TransitEncrypt.tsx index ed095f4..431fd0c 100644 --- a/src/pages/Secrets/Transit/TransitEncrypt.tsx +++ b/src/pages/Secrets/Transit/TransitEncrypt.tsx @@ -81,7 +81,7 @@ export class TransitEncryptPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/Transit/TransitRewrap.tsx b/src/pages/Secrets/Transit/TransitRewrap.tsx index e498eec..efdb0ee 100644 --- a/src/pages/Secrets/Transit/TransitRewrap.tsx +++ b/src/pages/Secrets/Transit/TransitRewrap.tsx @@ -96,7 +96,7 @@ export class TransitRewrapPage extends Page { async renderPageTitle(): Promise { render( - , + , this.router.pageTitleElement, ); } diff --git a/src/pages/Secrets/Transit/TransitView.tsx b/src/pages/Secrets/Transit/TransitView.tsx index 05884f5..85a017d 100644 --- a/src/pages/Secrets/Transit/TransitView.tsx +++ b/src/pages/Secrets/Transit/TransitView.tsx @@ -98,7 +98,7 @@ export class TransitViewPage extends Page { } async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + render(, this.router.pageTitleElement); } get name(): string { diff --git a/src/pages/Secrets/Transit/TransitViewSecret.tsx b/src/pages/Secrets/Transit/TransitViewSecret.tsx index 3ed6a15..3f636dd 100644 --- a/src/pages/Secrets/Transit/TransitViewSecret.tsx +++ b/src/pages/Secrets/Transit/TransitViewSecret.tsx @@ -53,7 +53,7 @@ export class TransitViewSecretPage extends Page { } async renderPageTitle(): Promise { - render(, this.router.pageTitleElement); + render(, this.router.pageTitleElement); } get name(): string { diff --git a/src/state/storage/StorageType.ts b/src/state/storage/StorageType.ts index 5f839ec..2c94b8c 100644 --- a/src/state/storage/StorageType.ts +++ b/src/state/storage/StorageType.ts @@ -2,4 +2,4 @@ export interface StorageType { clear(): void; getItem(key: string): string; setItem(key: string, value: string); -} \ No newline at end of file +}