From dfbfcea2533898be155205372d9d7c70962675e1 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sun, 23 May 2021 13:36:18 +0100 Subject: [PATCH] Add tsx syntax to AuthHome. --- src/pages/Access/Auth/AuthHome.ts | 75 ----------------------------- src/pages/Access/Auth/AuthHome.tsx | 76 ++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 75 deletions(-) delete mode 100644 src/pages/Access/Auth/AuthHome.ts create mode 100644 src/pages/Access/Auth/AuthHome.tsx diff --git a/src/pages/Access/Auth/AuthHome.ts b/src/pages/Access/Auth/AuthHome.ts deleted file mode 100644 index fb4c680..0000000 --- a/src/pages/Access/Auth/AuthHome.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { AuthMethod } from "../../../api/types/auth"; -import { Page } from "../../../types/Page"; -import { listAuth } from "../../../api/auth/listAuth"; -import { makeElement } from "z-makeelement"; -import { objectToMap } from "../../../utils"; -import i18next from "i18next"; - -export function AuthListElement(page: Page, path: string, method: AuthMethod): HTMLElement { - const isClickable = method.type != "token"; - - return makeElement({ - tag: "div", - class: ["uk-padding-small", "uk-background-secondary"], - children: [ - makeElement({ - tag: isClickable ? "a" : "span", - class: "uk-h4 uk-margin-bottom", - text: path, - onclick: async () => { - page.state.authPath = path; - if (method.type == "userpass") { - await page.router.changePage("USERPASS_USERS_LIST"); - } - }, - }), - makeElement({ - tag: "span", - class: "uk-text-muted", - text: ` (${method.accessor})`, - }), - makeElement({ - tag: "div", - class: "uk-margin-top", - children: [ - makeElement({ - tag: "button", - class: "uk-button uk-button-small uk-button-primary", - text: i18next.t("auth_home_view_config"), - onclick: async () => { - page.state.baseMount = path; - await page.router.changePage("AUTH_VIEW_CONFIG"); - }, - }), - makeElement({ - tag: "button", - class: "uk-button uk-button-small uk-button-primary", - text: i18next.t("auth_home_edit_config"), - }), - ], - }), - ], - }); -} - -export class AuthHomePage extends Page { - constructor() { - super(); - } - async goBack(): Promise { - await this.router.changePage("ACCESS_HOME"); - } - async render(): Promise { - this.state.secretPath = []; - - const authList = objectToMap(await listAuth()) as Map; - const contentElement = makeElement({ tag: "div" }); - await this.router.setPageContent(contentElement); - for (const [path, details] of authList) { - contentElement.appendChild(AuthListElement(this, path, details)); - } - } - get name(): string { - return i18next.t("auth_home_title"); - } -} diff --git a/src/pages/Access/Auth/AuthHome.tsx b/src/pages/Access/Auth/AuthHome.tsx new file mode 100644 index 0000000..9267f72 --- /dev/null +++ b/src/pages/Access/Auth/AuthHome.tsx @@ -0,0 +1,76 @@ +import { AuthMethod } from "../../../api/types/auth"; +import { JSX, render } from "preact"; +import { Page } from "../../../types/Page"; +import { listAuth } from "../../../api/auth/listAuth"; +import { notImplemented } from "../../../pageUtils"; +import { objectToMap } from "../../../utils"; +import i18next from "i18next"; + +export type AuthListElementProps = { + page: Page; + path: string; + method: AuthMethod; +}; + +export function AuthListElement(props: AuthListElementProps): JSX.Element { + const isClickable = props.method.type != "token"; + + const onHeaderLinkClick = async (props: AuthListElementProps) => { + props.page.state.authPath = props.path; + if (props.method.type == "userpass") { + await props.page.router.changePage("USERPASS_USERS_LIST"); + } + }; + + return ( +
+ {isClickable ? ( + onHeaderLinkClick(props)}> + {props.path} + + ) : ( + {props.path} + )} + {` (${props.method.accessor})`} +
+ + +
+
+ ); +} + +export class AuthHomePage extends Page { + constructor() { + super(); + } + async goBack(): Promise { + await this.router.changePage("ACCESS_HOME"); + } + async render(): Promise { + this.state.secretPath = []; + const authList = objectToMap(await listAuth()) as Map; + + render( +
+ {Array.from(authList).map((values: [string, AuthMethod]) => ( + + ))} +
, + this.router.pageContentElement, + ); + } + get name(): string { + return i18next.t("auth_home_title"); + } +}