diff --git a/src/pages/Secrets/TOTP/TOTPView.tsx b/src/pages/Secrets/TOTP/TOTPView.tsx index 87e932d..6f06b1b 100644 --- a/src/pages/Secrets/TOTP/TOTPView.tsx +++ b/src/pages/Secrets/TOTP/TOTPView.tsx @@ -4,37 +4,36 @@ import { Page } from "../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; import { getTOTPCode } from "../../../api/totp/getTOTPCode"; import { getTOTPKeys } from "../../../api/totp/getTOTPKeys"; -import { makeElement } from "z-makeelement"; -import { objectToMap } from "../../../utils"; import { setErrorText } from "../../../pageUtils"; import i18next from "i18next"; -import { render, JSX } from "preact"; +import { render, JSX, Component } from "preact"; -export interface TOTPListElement extends HTMLElement { - setCode(code: string): void; -} -function quickHash(str: string): string { - var hash = 0; - if (str.length == 0) { - return String(hash).toString(); + +export class RefreshingTOTPGridItem extends Component<{ baseMount: string; totpKey: string }, { totpValue: string }> { + constructor() { + super(); + this.state = { totpValue: "" }; } - for (var i = 0; i < str.length; i++) { - var char = str.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; + timer: unknown; + + componentDidMount(): void { + this.timer = setInterval(() => { + getTOTPCode(this.props.baseMount, this.props.totpKey).then((code) => { + this.setState({ totpValue: code }); + }) + this.setState({}); + }, 3000); } - return String(hash).toString(); -} - -export function TOTPGridItem(props: { item_key: string, item_value: string }): JSX.Element { - return ( -
{i18next.t("totp_view_loading")}
{i18next.t("totp_view_empty")}
+ } else { + setErrorText(error.message); + } + } + })()} +