diff --git a/src/ThemeLoader.tsx b/src/ThemeLoader.tsx index c2b1640..55dec7a 100644 --- a/src/ThemeLoader.tsx +++ b/src/ThemeLoader.tsx @@ -1,5 +1,5 @@ import { Component } from "preact"; -import { settings } from "./globalSettings"; +import { settings } from "./globals/globalSettings"; // @ts-ignore import style_dark from "./scss/main-dark.scss" assert { type: "css" }; diff --git a/src/api/apiUtils.ts b/src/api/apiUtils.ts index eb7766c..b077f10 100644 --- a/src/api/apiUtils.ts +++ b/src/api/apiUtils.ts @@ -1,6 +1,6 @@ import { BaseAPIResponse } from "./types/api"; import { DoesNotExistError } from "../types/internalErrors"; -import { settings } from "../globalSettings"; +import { settings } from "../globals/globalSettings"; export function getHeaders(): Record { return { diff --git a/src/globalSettings.ts b/src/globalSettings.ts deleted file mode 100644 index 4e120c2..0000000 --- a/src/globalSettings.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { Settings } from "./settings/Settings"; -export const settings = new Settings(); diff --git a/src/globalAPI.ts b/src/globals/globalAPI.ts similarity index 71% rename from src/globalAPI.ts rename to src/globals/globalAPI.ts index 58de8b4..3f2445b 100644 --- a/src/globalAPI.ts +++ b/src/globals/globalAPI.ts @@ -1,4 +1,4 @@ -import { API } from "./api/API"; +import { API } from "../api/API"; import { settings } from "./globalSettings"; export const api = new API(settings); diff --git a/src/globals/globalSettings.ts b/src/globals/globalSettings.ts new file mode 100644 index 0000000..35fee04 --- /dev/null +++ b/src/globals/globalSettings.ts @@ -0,0 +1,2 @@ +import { Settings } from "../settings/Settings"; +export const settings = new Settings(); diff --git a/src/main.tsx b/src/main.tsx index 4dbac5e..6fecf2f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -27,13 +27,13 @@ import translations from "./translations/index.mjs"; import { Main } from "./pages"; import { NavBar } from "./ui/elements/NavBar"; import { ThemeLoader } from "./ThemeLoader"; -import { api } from "./globalAPI"; -import { formatDistance } from "./formatDistance"; +import { api } from "./globals/globalAPI"; +import { formatDistance } from "./utils/formatDistance"; import { getCurrentUrl, route } from "preact-router"; -import { pageChecks } from "./pageUtils"; +import { pageChecks } from "./pageChecks"; import { playground } from "./playground"; import { render } from "preact"; -import { settings } from "./globalSettings"; +import { settings } from "./globals/globalSettings"; import i18next from "i18next"; async function onLoad(): Promise { diff --git a/src/pageUtils.ts b/src/pageChecks.ts similarity index 60% rename from src/pageUtils.ts rename to src/pageChecks.ts index fe4bfff..eae30ae 100644 --- a/src/pageUtils.ts +++ b/src/pageChecks.ts @@ -1,9 +1,6 @@ import { API } from "./api/API"; import { Settings } from "./settings/Settings"; import { route } from "preact-router"; -import ClipboardJS from "clipboard"; -import UIkit from "uikit"; -import i18next from "i18next"; export async function pageChecks(url: string, api: API, settings: Settings): Promise { if (url.startsWith("/set_language")) return; @@ -39,24 +36,4 @@ export async function pageChecks(url: string, api: API, settings: Settings): Pro return true; } return false; -} - -export function addClipboardNotifications(clipboard: ClipboardJS, timeout = 1000): void { - clipboard.on("success", () => { - UIkit.notification(i18next.t("notification_copy_success"), { - status: "success", - timeout: timeout, - }); - }); - clipboard.on("error", function (e: Error) { - UIkit.notification( - i18next.t("notification_copy_error", { - error: e.message, - }), - { - status: "danger", - timeout: timeout, - }, - ); - }); -} +} \ No newline at end of file diff --git a/src/pages.tsx b/src/pages.tsx index f279cce..86c85b4 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -1,6 +1,6 @@ -import { api } from "./globalAPI"; -import { pageChecks } from "./pageUtils"; -import { settings } from "./globalSettings"; +import { api } from "./globals/globalAPI"; +import { pageChecks } from "./pageChecks"; +import { settings } from "./globals/globalSettings"; import Router from "preact-router"; import { AccessHomePage } from "./ui/pages/Access/AccessHome"; diff --git a/src/playground.tsx b/src/playground.tsx index 3444907..c70b72f 100644 --- a/src/playground.tsx +++ b/src/playground.tsx @@ -1,5 +1,5 @@ import { Settings } from "./settings/Settings"; -import { settings } from "./globalSettings"; +import { settings } from "./globals/globalSettings"; // Playground is a way to debug and test things. // Anything you put in here is gonna be run on page initial load diff --git a/src/ui/elements/CopyableBox.tsx b/src/ui/elements/CopyableBox.tsx index 56cf724..049f53a 100644 --- a/src/ui/elements/CopyableBox.tsx +++ b/src/ui/elements/CopyableBox.tsx @@ -1,7 +1,7 @@ import { Button } from "./Button"; import { CodeBlock } from "./CodeBlock"; import { Component, JSX, createRef } from "preact"; -import { addClipboardNotifications } from "../../pageUtils"; +import { addClipboardNotifications } from "../../utils/clipboardNotifs"; import ClipboardJS from "clipboard"; import FileSaver from "file-saver"; import i18next from "i18next"; diff --git a/src/ui/elements/CopyableInputBox.tsx b/src/ui/elements/CopyableInputBox.tsx index a576b14..bacd32e 100644 --- a/src/ui/elements/CopyableInputBox.tsx +++ b/src/ui/elements/CopyableInputBox.tsx @@ -1,6 +1,6 @@ import { Component, JSX, createRef } from "preact"; import { MarginInline } from "./MarginInline"; -import { addClipboardNotifications } from "../../pageUtils"; +import { addClipboardNotifications } from "../../utils/clipboardNotifs"; import ClipboardJS from "clipboard"; import i18next from "i18next"; diff --git a/src/ui/pages/Home.tsx b/src/ui/pages/Home.tsx index d69d2c5..1a40d91 100644 --- a/src/ui/pages/Home.tsx +++ b/src/ui/pages/Home.tsx @@ -5,7 +5,7 @@ import { Margin } from "../elements/Margin"; import { PageTitle } from "../elements/PageTitle"; import { Tile } from "../elements/Tile"; import { TokenInfo } from "../../api/types/token"; -import { pageChecks } from "../../pageUtils"; +import { pageChecks } from "../../pageChecks"; import { route } from "preact-router"; import { sendErrorNotification } from "../elements/ErrorMessage"; import i18next from "i18next"; diff --git a/src/ui/pages/Me.tsx b/src/ui/pages/Me.tsx index 56fecc4..54388d5 100644 --- a/src/ui/pages/Me.tsx +++ b/src/ui/pages/Me.tsx @@ -4,7 +4,7 @@ import { DefaultPageProps } from "../../types/DefaultPageProps"; import { ErrorMessage } from "../elements/ErrorMessage"; import { Margin } from "../elements/Margin"; import { PageTitle } from "../elements/PageTitle"; -import { addClipboardNotifications } from "../../pageUtils"; +import { addClipboardNotifications } from "../../utils/clipboardNotifs"; import { route } from "preact-router"; import ClipboardJS from "clipboard"; import i18next from "i18next"; diff --git a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx index e6767ce..40e6fed 100644 --- a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx +++ b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx @@ -8,7 +8,7 @@ import { Form } from "../../../elements/Form"; import { InputWithTitle } from "../../../elements/InputWithTitle"; import { Margin } from "../../../elements/Margin"; import { SecretTitleElement } from "../SecretTitleElement"; -import { fileToBase64 } from "../../../../htmlUtils"; +import { fileToBase64 } from "../../../../utils/fileToBase64"; import i18next from "i18next"; export class TransitDecrypt extends Component { diff --git a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx index 5d4a747..f87285c 100644 --- a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx +++ b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx @@ -8,7 +8,7 @@ import { Form } from "../../../elements/Form"; import { InputWithTitle } from "../../../elements/InputWithTitle"; import { Margin } from "../../../elements/Margin"; import { SecretTitleElement } from "../SecretTitleElement"; -import { fileToBase64 } from "../../../../htmlUtils"; +import { fileToBase64 } from "../../../../utils/fileToBase64"; import i18next from "i18next"; export class TransitEncrypt extends Component { diff --git a/src/ui/pages/SetLanguage.tsx b/src/ui/pages/SetLanguage.tsx index fa3750c..ece47bb 100644 --- a/src/ui/pages/SetLanguage.tsx +++ b/src/ui/pages/SetLanguage.tsx @@ -9,7 +9,7 @@ import { Form } from "../elements/Form"; import { Margin } from "../elements/Margin"; import { MarginInline } from "../elements/MarginInline"; import { PageTitle } from "../elements/PageTitle"; -import { getTranslationCompletePercentage } from "../../translationUtils"; +import { getTranslationCompletePercentage } from "../../utils/translationUtils"; import { route } from "preact-router"; import i18next from "i18next"; diff --git a/src/ui/pages/Settings/GeneralSettings.tsx b/src/ui/pages/Settings/GeneralSettings.tsx index 122f6a7..bb63126 100644 --- a/src/ui/pages/Settings/GeneralSettings.tsx +++ b/src/ui/pages/Settings/GeneralSettings.tsx @@ -4,7 +4,7 @@ import { InputWithTitle } from "../../elements/InputWithTitle"; import i18next from "i18next"; // @ts-ignore -import { getTranslationCompletePercentage } from "../../../translationUtils"; +import { getTranslationCompletePercentage } from "../../../utils/translationUtils"; import { settingsSavedNotification } from "./Settings"; import translations from "../../../translations/index.mjs"; diff --git a/src/utils/clipboardNotifs.ts b/src/utils/clipboardNotifs.ts new file mode 100644 index 0000000..9037790 --- /dev/null +++ b/src/utils/clipboardNotifs.ts @@ -0,0 +1,22 @@ +import i18next from "i18next"; +import { UIkit } from "uikit"; + +export function addClipboardNotifications(clipboard: ClipboardJS, timeout = 1000): void { + clipboard.on("success", () => { + UIkit.notification(i18next.t("notification_copy_success"), { + status: "success", + timeout: timeout, + }); + }); + clipboard.on("error", function (e: Error) { + UIkit.notification( + i18next.t("notification_copy_error", { + error: e.message, + }), + { + status: "danger", + timeout: timeout, + }, + ); + }); +} diff --git a/src/htmlUtils.ts b/src/utils/fileToBase64.ts similarity index 100% rename from src/htmlUtils.ts rename to src/utils/fileToBase64.ts diff --git a/src/formatDistance.ts b/src/utils/formatDistance.ts similarity index 100% rename from src/formatDistance.ts rename to src/utils/formatDistance.ts diff --git a/src/translationUtils.ts b/src/utils/translationUtils.ts similarity index 94% rename from src/translationUtils.ts rename to src/utils/translationUtils.ts index 296c5ac..4f194f3 100644 --- a/src/translationUtils.ts +++ b/src/utils/translationUtils.ts @@ -1,5 +1,5 @@ // @ts-ignore -import translations from "./translations/index.mjs"; +import translations from "../translations/index.mjs"; export function arrayDiff( a: string[],