1
0
Fork 0

Redo some async things.

This commit is contained in:
Kitteh 2021-05-12 14:54:25 +01:00
parent 799931f31a
commit 74aabc5d74
6 changed files with 49 additions and 42 deletions

View file

@ -53,13 +53,13 @@ export class KeyValueNewPage extends Page {
}) as HTMLFormElement; }) as HTMLFormElement;
setPageContent(this.addKVNewForm); setPageContent(this.addKVNewForm);
this.addKVNewForm.addEventListener("submit", function (e: Event) { this.addKVNewForm.addEventListener("submit", (e: Event) => {
e.preventDefault(); e.preventDefault();
(this as KeyValueNewPage).newKVSecretHandleForm(); void this.newKVSecretHandleForm();
}.bind(this)); });
} }
newKVSecretHandleForm(): void { async newKVSecretHandleForm(): Promise<void> {
const formData = new FormData(this.addKVNewForm); const formData = new FormData(this.addKVNewForm);
const path = formData.get("path") as string; const path = formData.get("path") as string;
let keyData = {}; let keyData = {};
@ -68,18 +68,20 @@ export class KeyValueNewPage extends Page {
keyData = { "key": "value" }; keyData = { "key": "value" };
} }
createOrUpdateSecret( try {
pageState.currentBaseMount, await createOrUpdateSecret(
pageState.currentMountType, pageState.currentBaseMount,
pageState.currentSecretPath, pageState.currentMountType,
path, pageState.currentSecretPath,
keyData path,
).then(_ => { keyData
)
changePage("KEY_VALUE_VIEW"); changePage("KEY_VALUE_VIEW");
return; } catch (e: unknown) {
}).catch((e: Error) => { const error = e as Error;
setErrorText(e.message); setErrorText(error.message);
}); }
} }
get titleSuffix(): string { get titleSuffix(): string {

View file

@ -24,7 +24,7 @@ export class TOTPViewPage extends Page {
refresher: number; refresher: number;
totpListElements: Record<string, TOTPListElement>; totpListElements: Record<string, TOTPListElement>;
render(): void { async render(): Promise<void> {
setTitleElement(pageState); setTitleElement(pageState);
const totpList = makeElement({ tag: "div" }); const totpList = makeElement({ tag: "div" });
setPageContent(makeElement({ setPageContent(makeElement({
@ -47,30 +47,33 @@ export class TOTPViewPage extends Page {
})); }));
getTOTPKeys(pageState.currentBaseMount).then(res => { try {
res.forEach(function (totpKeyName) { const res = await getTOTPKeys(pageState.currentBaseMount);
const totpListElement = (this as TOTPViewPage).makeTOTPListElement(totpKeyName); for (const totpKeyName in res.entries()) {
const totpListElement = this.makeTOTPListElement(totpKeyName);
totpList.appendChild(totpListElement); totpList.appendChild(totpListElement);
(this as TOTPViewPage).totpListElements[totpKeyName] = totpListElement; this.totpListElements[totpKeyName] = totpListElement;
void (this as TOTPViewPage).updateTOTPElement(totpKeyName, totpListElement); void this.updateTOTPElement(totpKeyName, totpListElement);
}, this); }
document.getElementById("loadingText").remove(); document.getElementById("loadingText").remove();
}).catch((e: Error) => { } catch (e: unknown) {
if (e == DoesNotExistError) { const error = e as Error;
if (error == DoesNotExistError) {
const loadingText = document.getElementById("loadingText"); const loadingText = document.getElementById("loadingText");
loadingText.innerText = i18next.t("totp_view_empty"); loadingText.innerText = i18next.t("totp_view_empty");
} else { } else {
setErrorText(e.message); setErrorText(error.message);
} }
}); }
const totpRefresher = () => {
void Promise.all(Array.from(objectToMap(this.totpListElements)).map((kv: [string, TOTPListElement]) => { const totpRefresher = async () => {
await Promise.all(Array.from(objectToMap(this.totpListElements)).map((kv: [string, TOTPListElement]) => {
return this.updateTOTPElement(...kv); return this.updateTOTPElement(...kv);
})) }))
} }
void totpRefresher(); await totpRefresher();
this.refresher = setInterval(totpRefresher, 3000) as unknown as number; this.refresher = setInterval(() => { void totpRefresher(); }, 3000) as unknown as number;
} }
cleanup(): void { cleanup(): void {

View file

@ -71,10 +71,10 @@ export class TransitDecryptPage extends Page {
] ]
}) as HTMLFormElement; }) as HTMLFormElement;
setPageContent(this.transitDecryptForm); setPageContent(this.transitDecryptForm);
this.transitDecryptForm.addEventListener("submit", async function (e: Event) { this.transitDecryptForm.addEventListener("submit", (e: Event) => {
e.preventDefault(); e.preventDefault();
await (this as TransitDecryptPage).transitDecryptFormHandler(); void this.transitDecryptFormHandler();
}.bind(this)); });
} }
async transitDecryptFormHandler(): Promise<void> { async transitDecryptFormHandler(): Promise<void> {

View file

@ -74,10 +74,10 @@ export class TransitEncryptPage extends Page {
}) as HTMLFormElement; }) as HTMLFormElement;
setPageContent(this.transitEncryptForm); setPageContent(this.transitEncryptForm);
this.transitEncryptForm.addEventListener("submit", async function (e: Event) { this.transitEncryptForm.addEventListener("submit", (e: Event) => {
e.preventDefault(); e.preventDefault();
await (this as TransitEncryptPage).transitEncryptFormHandler(); void this.transitEncryptFormHandler();
}.bind(this)); });
} }
async transitEncryptFormHandler(): Promise<void> { async transitEncryptFormHandler(): Promise<void> {

View file

@ -79,10 +79,11 @@ export class TransitRewrapPage extends Page {
] ]
}) as HTMLFormElement; }) as HTMLFormElement;
setPageContent(this.transitRewrapForm); setPageContent(this.transitRewrapForm);
this.transitRewrapForm.addEventListener("submit", async function (e: Event) {
this.transitRewrapForm.addEventListener("submit", (e: Event) => {
e.preventDefault(); e.preventDefault();
await (this as TransitRewrapPage).transitRewrapFormHandler(); void this.transitRewrapFormHandler();
}.bind(this)); });
} }
async transitRewrapFormHandler(): Promise<void> { async transitRewrapFormHandler(): Promise<void> {

View file

@ -5,8 +5,9 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"module": "es6", "module": "es6",
"target": "es2019", "target": "es2019",
"jsx": "react", "strictBindCallApply": true,
"noImplicitThis": true,
"allowJs": true, "allowJs": true,
"moduleResolution": "node", "moduleResolution": "node"
} }
} }