1
0
Fork 0

Add typing to NewTOTP.ts.

This commit is contained in:
Kitteh 2021-05-08 02:56:08 +01:00
parent 5971ae7bd8
commit 489792fb8d
2 changed files with 21 additions and 14 deletions

View file

@ -7,7 +7,7 @@ import { KeyValueVersionsPage } from "./pages/KeyValue/KeyValueVersions.js";
import { KeyValueViewPage } from "./pages/KeyValue/KeyValueView.js"; import { KeyValueViewPage } from "./pages/KeyValue/KeyValueView.js";
import { LoginPage } from "./pages/Login"; import { LoginPage } from "./pages/Login";
import { MePage } from "./pages/Me"; import { MePage } from "./pages/Me";
import { NewTOTPPage } from "./pages/TOTP/NewTOTP.js"; import { NewTOTPPage } from "./pages/TOTP/NewTOTP";
import { Page } from "./types/Page"; import { Page } from "./types/Page";
import { PwGenPage } from "./pages/PwGen"; import { PwGenPage } from "./pages/PwGen";
import { SetLanguagePage } from "./pages/SetLanguage"; import { SetLanguagePage } from "./pages/SetLanguage";

View file

@ -4,21 +4,29 @@ import { Page } from "../../types/Page";
import { addNewTOTP } from "../../api/addNewTOTP"; import { addNewTOTP } from "../../api/addNewTOTP";
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "../../htmlUtils";
import { pageState } from "../../globalPageState.ts"; import { pageState } from "../../globalPageState";
import i18next from 'i18next'; import i18next from 'i18next';
function replaceAll(str: string, replace: string, replaceWith: string): string {
return str.replace(new RegExp(replace, 'g'), replaceWith);
}
function removeDashSpaces(str: string): string {
str = replaceAll(str, "-", "");
str = replaceAll(str, " ", "");
return str;
}
export class NewTOTPPage extends Page { export class NewTOTPPage extends Page {
constructor() { constructor() {
super(); super();
} }
goBack() { goBack(): void {
changePage("TOTP"); changePage("TOTP");
} }
render() { render(): void {
setTitleElement(pageState); setTitleElement(pageState);
let totpForm = makeElement({ const totpForm = makeElement({
tag: "form", tag: "form",
children: [ children: [
Margin(makeElement({ Margin(makeElement({
@ -67,17 +75,16 @@ export class NewTOTPPage extends Page {
} }
})) }))
] ]
}) as HTMLFormElement;
});
setPageContent(totpForm); setPageContent(totpForm);
totpForm.addEventListener("submit", function (e) { totpForm.addEventListener("submit", function (e) {
e.preventDefault(); e.preventDefault();
let formData = new FormData(totpForm); const formData = new FormData(totpForm);
let parms = { const parms = {
url: formData.get("uri"), url: formData.get("uri") as string,
key: formData.get("key").replaceAll("-", "").replaceAll(" ", "").toUpperCase(), key: removeDashSpaces(formData.get("key") as string).toUpperCase(),
name: formData.get("name"), name: formData.get("name") as string,
generate: false generate: false
}; };
addNewTOTP(pageState.currentBaseMount, parms).then(_ => { addNewTOTP(pageState.currentBaseMount, parms).then(_ => {
@ -88,11 +95,11 @@ export class NewTOTPPage extends Page {
}); });
} }
get titleSuffix() { get titleSuffix(): string {
return i18next.t("totp_new_suffix"); return i18next.t("totp_new_suffix");
} }
get name() { get name(): string {
return i18next.t("totp_new_title"); return i18next.t("totp_new_title");
} }
} }