diff --git a/src/pages/SetLanguage.ts b/src/pages/SetLanguage.ts deleted file mode 100644 index 6b69cec..0000000 --- a/src/pages/SetLanguage.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Form } from "../elements/Form"; -import { Margin } from "../elements/Margin"; -import { Page } from "../types/Page"; -import { makeElement } from "z-makeelement"; -import { reloadNavBar } from "../elements/NavBar"; -import i18next from "i18next"; - -// @ts-ignore -import translations from "../translations/index.mjs"; - -const languageIDs = Object.getOwnPropertyNames(translations); - -export class SetLanguagePage extends Page { - constructor() { - super(); - } - async render(): Promise { - await this.router.setPageContent( - Form( - [ - Margin( - makeElement({ - tag: "select", - class: ["uk-select", "uk-form-width-large"], - attributes: { - name: "language", - }, - children: languageIDs.map(function (languageID) { - return makeElement({ - tag: "option", - text: i18next.getFixedT(languageID, null)("language_name"), - attributes: { value: languageID }, - }); - }), - }), - ), - makeElement({ - tag: "p", - id: "errorText", - class: "uk-text-danger", - }), - makeElement({ - tag: "button", - class: ["uk-button", "uk-button-primary"], - text: i18next.t("set_language_btn"), - attributes: { - type: "submit", - }, - }), - ], - async (form: HTMLFormElement) => { - const formData = new FormData(form); - - const language = formData.get("language") as string; - this.state.language = language; - - const t = await i18next.changeLanguage(language); - this.state.pageDirection = t("language_direction"); - reloadNavBar(this.router); - await this.router.changePage("HOME"); - }, - ), - ); - } - get name(): string { - return i18next.t("set_language_title"); - } -} diff --git a/src/pages/SetLanguage.tsx b/src/pages/SetLanguage.tsx new file mode 100644 index 0000000..468f57f --- /dev/null +++ b/src/pages/SetLanguage.tsx @@ -0,0 +1,55 @@ +// @ts-ignore +import translations from "../translations/index.mjs"; +// ts-unignore + +import { Form } from "../elements/ReactForm"; +import { Margin } from "../elements/ReactMargin"; +import { MarginInline } from "../elements/ReactMarginInline"; +import { Page } from "../types/Page"; +import { reloadNavBar } from "../elements/NavBar"; +import { render } from "preact"; +import i18next from "i18next"; + +const languageIDs = Object.getOwnPropertyNames(translations); + +export class SetLanguagePage extends Page { + constructor() { + super(); + } + async render(): Promise { + render( +
this.onSubmit(data)}> + + + +

+ + + +

, + this.router.pageContentElement, + ); + } + + async onSubmit(data: FormData): Promise { + const language = data.get("language") as string; + this.state.language = language; + + const t = await i18next.changeLanguage(language); + this.state.pageDirection = t("language_direction"); + reloadNavBar(this.router); + await this.router.changePage("HOME"); + } + + get name(): string { + return i18next.t("set_language_title"); + } +}