Change how page titles work, updating to z-pagerouter 1.0.2.
This commit is contained in:
parent
ac9564eb60
commit
fc66591cc3
|
@ -43,6 +43,6 @@
|
||||||
"webpack-cli": "^4.7.0",
|
"webpack-cli": "^4.7.0",
|
||||||
"webpack-dev-server": "^3.11.2",
|
"webpack-dev-server": "^3.11.2",
|
||||||
"z-makeelement": "^1.0.3",
|
"z-makeelement": "^1.0.3",
|
||||||
"z-pagerouter": "^1.0.1"
|
"z-pagerouter": "^1.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,11 @@ export class KeyValueDeletePage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("kv_delete_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("kv_delete_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -61,8 +61,11 @@ export class KeyValueNewPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("kv_new_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("kv_new_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -162,8 +162,8 @@ export class KeyValueSecretPage extends Page {
|
||||||
document.getElementById("loadingText").remove();
|
document.getElementById("loadingText").remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router);
|
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { createOrUpdateSecret } from "../../../api/kv/createOrUpdateSecret";
|
import { createOrUpdateSecret } from "../../../api/kv/createOrUpdateSecret";
|
||||||
import { getSecret } from "../../../api/kv/getSecret";
|
import { getSecret } from "../../../api/kv/getSecret";
|
||||||
import { makeElement } from "z-makeelement";
|
import { makeElement } from "z-makeelement";
|
||||||
|
import { render } from "preact";
|
||||||
import { setErrorText } from "../../../pageUtils";
|
import { setErrorText } from "../../../pageUtils";
|
||||||
import { sortedObjectMap, verifyJSONString } from "../../../utils";
|
import { sortedObjectMap, verifyJSONString } from "../../../utils";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
@ -79,8 +80,11 @@ export class KeyValueSecretEditPage extends Page {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("kv_sec_edit_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("kv_sec_edit_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
|
@ -42,8 +42,11 @@ export class KeyValueVersionsPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("kv_sec_versions_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("kv_sec_versions_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -89,8 +89,8 @@ export class KeyValueViewPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router);
|
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { JSX } from "preact/jsx-runtime";
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "../../PageState";
|
import { PageState } from "../../PageState";
|
||||||
import { makeElement } from "z-makeelement";
|
|
||||||
|
|
||||||
function currentTitleSecretText(state: PageState): string {
|
function currentTitleSecretText(state: PageState): string {
|
||||||
let secretItemText = state.secretItem;
|
let secretItemText = state.secretItem;
|
||||||
|
@ -8,15 +8,20 @@ function currentTitleSecretText(state: PageState): string {
|
||||||
return secretItemText;
|
return secretItemText;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
|
type SecretTitleElementProps = {
|
||||||
|
router: PageRouter;
|
||||||
|
suffix?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element {
|
||||||
|
const router = props.router;
|
||||||
|
const suffix = props.suffix || "";
|
||||||
const state = router.state as PageState;
|
const state = router.state as PageState;
|
||||||
const titleElement = makeElement({
|
|
||||||
tag: "div",
|
return (
|
||||||
children: [
|
<div>
|
||||||
makeElement({
|
<a
|
||||||
tag: "a",
|
onClick={async () => {
|
||||||
text: state.baseMount + " ",
|
|
||||||
onclick: async () => {
|
|
||||||
state.secretPath = [];
|
state.secretPath = [];
|
||||||
state.secretItem = "";
|
state.secretItem = "";
|
||||||
state.secretVersion = null;
|
state.secretVersion = null;
|
||||||
|
@ -28,32 +33,25 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
|
||||||
} else if (state.secretMountType == "transit") {
|
} else if (state.secretMountType == "transit") {
|
||||||
await router.changePage("TRANSIT_VIEW");
|
await router.changePage("TRANSIT_VIEW");
|
||||||
}
|
}
|
||||||
},
|
}}
|
||||||
}),
|
>
|
||||||
...state.secretPath.map((secretPath, index, secretPaths) => {
|
{state.baseMount + " "}
|
||||||
return makeElement({
|
</a>
|
||||||
tag: "a",
|
{...state.secretPath.map((secretPath, index, secretPaths) => (
|
||||||
text: secretPath + " ",
|
<a
|
||||||
onclick: async () => {
|
onClick={async () => {
|
||||||
state.secretVersion = null;
|
state.secretVersion = null;
|
||||||
if (state.secretMountType.startsWith("kv")) {
|
if (state.secretMountType.startsWith("kv")) {
|
||||||
state.secretPath = secretPaths.slice(0, index + 1);
|
state.secretPath = secretPaths.slice(0, index + 1);
|
||||||
await router.changePage("KEY_VALUE_VIEW");
|
await router.changePage("KEY_VALUE_VIEW");
|
||||||
}
|
}
|
||||||
},
|
}}
|
||||||
});
|
>
|
||||||
}),
|
{secretPath + " "}
|
||||||
makeElement({
|
</a>
|
||||||
tag: "span",
|
))}
|
||||||
condition: state.secretItem.length != 0,
|
{state.secretItem.length != 0 && <span>{currentTitleSecretText(state)}</span>}
|
||||||
text: currentTitleSecretText(state),
|
{suffix.length != 0 && <span>{suffix}</span>}
|
||||||
}),
|
</div>
|
||||||
makeElement({
|
);
|
||||||
tag: "span",
|
|
||||||
condition: suffix.length != 0,
|
|
||||||
text: suffix,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
return titleElement;
|
|
||||||
}
|
}
|
|
@ -35,8 +35,11 @@ export class TOTPDeletePage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("totp_delete_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("totp_delete_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -81,8 +81,11 @@ export class TOTPNewPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("totp_new_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("totp_new_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -114,8 +114,8 @@ export class TOTPViewPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router);
|
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -76,8 +76,11 @@ export class NewTransitKeyPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("transit_new_key_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("transit_new_key_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -82,8 +82,11 @@ export class TransitDecryptPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("transit_decrypt_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("transit_decrypt_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -79,8 +79,11 @@ export class TransitEncryptPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("transit_encrypt_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("transit_encrypt_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -94,8 +94,11 @@ export class TransitRewrapPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router, i18next.t("transit_rewrap_suffix"));
|
render(
|
||||||
|
<SecretTitleElement router={this.router} suffix={i18next.t("transit_rewrap_suffix")} />,
|
||||||
|
this.router.pageTitleElement,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -97,8 +97,8 @@ export class TransitViewPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router);
|
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -51,8 +51,8 @@ export class TransitViewSecretPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return await SecretTitleElement(this.router);
|
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -13,8 +13,8 @@ export class Page {
|
||||||
get name(): string {
|
get name(): string {
|
||||||
return "Page";
|
return "Page";
|
||||||
}
|
}
|
||||||
async getPageTitle(): Promise<Element | string> {
|
async renderPageTitle(): Promise<void> {
|
||||||
return this.name;
|
this.router.pageTitleElement.innerText = this.name;
|
||||||
}
|
}
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
await this.router.changePage("HOME");
|
await this.router.changePage("HOME");
|
||||||
|
|
Loading…
Reference in a new issue