move utils into utils and globals into globals
This commit is contained in:
parent
0695adec71
commit
e2042747b8
|
@ -1,5 +1,5 @@
|
||||||
import { Component } from "preact";
|
import { Component } from "preact";
|
||||||
import { settings } from "./globalSettings";
|
import { settings } from "./globals/globalSettings";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import style_dark from "./scss/main-dark.scss" assert { type: "css" };
|
import style_dark from "./scss/main-dark.scss" assert { type: "css" };
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { BaseAPIResponse } from "./types/api";
|
import { BaseAPIResponse } from "./types/api";
|
||||||
import { DoesNotExistError } from "../types/internalErrors";
|
import { DoesNotExistError } from "../types/internalErrors";
|
||||||
import { settings } from "../globalSettings";
|
import { settings } from "../globals/globalSettings";
|
||||||
|
|
||||||
export function getHeaders(): Record<string, string> {
|
export function getHeaders(): Record<string, string> {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
import { Settings } from "./settings/Settings";
|
|
||||||
export const settings = new Settings();
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { API } from "./api/API";
|
import { API } from "../api/API";
|
||||||
import { settings } from "./globalSettings";
|
import { settings } from "./globalSettings";
|
||||||
|
|
||||||
export const api = new API(settings);
|
export const api = new API(settings);
|
2
src/globals/globalSettings.ts
Normal file
2
src/globals/globalSettings.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import { Settings } from "../settings/Settings";
|
||||||
|
export const settings = new Settings();
|
|
@ -27,13 +27,13 @@ import translations from "./translations/index.mjs";
|
||||||
import { Main } from "./pages";
|
import { Main } from "./pages";
|
||||||
import { NavBar } from "./ui/elements/NavBar";
|
import { NavBar } from "./ui/elements/NavBar";
|
||||||
import { ThemeLoader } from "./ThemeLoader";
|
import { ThemeLoader } from "./ThemeLoader";
|
||||||
import { api } from "./globalAPI";
|
import { api } from "./globals/globalAPI";
|
||||||
import { formatDistance } from "./formatDistance";
|
import { formatDistance } from "./utils/formatDistance";
|
||||||
import { getCurrentUrl, route } from "preact-router";
|
import { getCurrentUrl, route } from "preact-router";
|
||||||
import { pageChecks } from "./pageUtils";
|
import { pageChecks } from "./pageChecks";
|
||||||
import { playground } from "./playground";
|
import { playground } from "./playground";
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import { settings } from "./globalSettings";
|
import { settings } from "./globals/globalSettings";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
async function onLoad(): Promise<void> {
|
async function onLoad(): Promise<void> {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import { API } from "./api/API";
|
import { API } from "./api/API";
|
||||||
import { Settings } from "./settings/Settings";
|
import { Settings } from "./settings/Settings";
|
||||||
import { route } from "preact-router";
|
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<boolean> {
|
export async function pageChecks(url: string, api: API, settings: Settings): Promise<boolean> {
|
||||||
if (url.startsWith("/set_language")) return;
|
if (url.startsWith("/set_language")) return;
|
||||||
|
@ -39,24 +36,4 @@ export async function pageChecks(url: string, api: API, settings: Settings): Pro
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { api } from "./globalAPI";
|
import { api } from "./globals/globalAPI";
|
||||||
import { pageChecks } from "./pageUtils";
|
import { pageChecks } from "./pageChecks";
|
||||||
import { settings } from "./globalSettings";
|
import { settings } from "./globals/globalSettings";
|
||||||
import Router from "preact-router";
|
import Router from "preact-router";
|
||||||
|
|
||||||
import { AccessHomePage } from "./ui/pages/Access/AccessHome";
|
import { AccessHomePage } from "./ui/pages/Access/AccessHome";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Settings } from "./settings/Settings";
|
import { Settings } from "./settings/Settings";
|
||||||
import { settings } from "./globalSettings";
|
import { settings } from "./globals/globalSettings";
|
||||||
|
|
||||||
// Playground is a way to debug and test things.
|
// Playground is a way to debug and test things.
|
||||||
// Anything you put in here is gonna be run on page initial load
|
// Anything you put in here is gonna be run on page initial load
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Button } from "./Button";
|
import { Button } from "./Button";
|
||||||
import { CodeBlock } from "./CodeBlock";
|
import { CodeBlock } from "./CodeBlock";
|
||||||
import { Component, JSX, createRef } from "preact";
|
import { Component, JSX, createRef } from "preact";
|
||||||
import { addClipboardNotifications } from "../../pageUtils";
|
import { addClipboardNotifications } from "../../utils/clipboardNotifs";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
import FileSaver from "file-saver";
|
import FileSaver from "file-saver";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Component, JSX, createRef } from "preact";
|
import { Component, JSX, createRef } from "preact";
|
||||||
import { MarginInline } from "./MarginInline";
|
import { MarginInline } from "./MarginInline";
|
||||||
import { addClipboardNotifications } from "../../pageUtils";
|
import { addClipboardNotifications } from "../../utils/clipboardNotifs";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Margin } from "../elements/Margin";
|
||||||
import { PageTitle } from "../elements/PageTitle";
|
import { PageTitle } from "../elements/PageTitle";
|
||||||
import { Tile } from "../elements/Tile";
|
import { Tile } from "../elements/Tile";
|
||||||
import { TokenInfo } from "../../api/types/token";
|
import { TokenInfo } from "../../api/types/token";
|
||||||
import { pageChecks } from "../../pageUtils";
|
import { pageChecks } from "../../pageChecks";
|
||||||
import { route } from "preact-router";
|
import { route } from "preact-router";
|
||||||
import { sendErrorNotification } from "../elements/ErrorMessage";
|
import { sendErrorNotification } from "../elements/ErrorMessage";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { DefaultPageProps } from "../../types/DefaultPageProps";
|
||||||
import { ErrorMessage } from "../elements/ErrorMessage";
|
import { ErrorMessage } from "../elements/ErrorMessage";
|
||||||
import { Margin } from "../elements/Margin";
|
import { Margin } from "../elements/Margin";
|
||||||
import { PageTitle } from "../elements/PageTitle";
|
import { PageTitle } from "../elements/PageTitle";
|
||||||
import { addClipboardNotifications } from "../../pageUtils";
|
import { addClipboardNotifications } from "../../utils/clipboardNotifs";
|
||||||
import { route } from "preact-router";
|
import { route } from "preact-router";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Form } from "../../../elements/Form";
|
||||||
import { InputWithTitle } from "../../../elements/InputWithTitle";
|
import { InputWithTitle } from "../../../elements/InputWithTitle";
|
||||||
import { Margin } from "../../../elements/Margin";
|
import { Margin } from "../../../elements/Margin";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { fileToBase64 } from "../../../../htmlUtils";
|
import { fileToBase64 } from "../../../../utils/fileToBase64";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
export class TransitDecrypt extends Component<DefaultPageProps, { plaintext: string }> {
|
export class TransitDecrypt extends Component<DefaultPageProps, { plaintext: string }> {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Form } from "../../../elements/Form";
|
||||||
import { InputWithTitle } from "../../../elements/InputWithTitle";
|
import { InputWithTitle } from "../../../elements/InputWithTitle";
|
||||||
import { Margin } from "../../../elements/Margin";
|
import { Margin } from "../../../elements/Margin";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { fileToBase64 } from "../../../../htmlUtils";
|
import { fileToBase64 } from "../../../../utils/fileToBase64";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
export class TransitEncrypt extends Component<DefaultPageProps, { ciphertext: string }> {
|
export class TransitEncrypt extends Component<DefaultPageProps, { ciphertext: string }> {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { Form } from "../elements/Form";
|
||||||
import { Margin } from "../elements/Margin";
|
import { Margin } from "../elements/Margin";
|
||||||
import { MarginInline } from "../elements/MarginInline";
|
import { MarginInline } from "../elements/MarginInline";
|
||||||
import { PageTitle } from "../elements/PageTitle";
|
import { PageTitle } from "../elements/PageTitle";
|
||||||
import { getTranslationCompletePercentage } from "../../translationUtils";
|
import { getTranslationCompletePercentage } from "../../utils/translationUtils";
|
||||||
import { route } from "preact-router";
|
import { route } from "preact-router";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { InputWithTitle } from "../../elements/InputWithTitle";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { getTranslationCompletePercentage } from "../../../translationUtils";
|
import { getTranslationCompletePercentage } from "../../../utils/translationUtils";
|
||||||
import { settingsSavedNotification } from "./Settings";
|
import { settingsSavedNotification } from "./Settings";
|
||||||
import translations from "../../../translations/index.mjs";
|
import translations from "../../../translations/index.mjs";
|
||||||
|
|
||||||
|
|
22
src/utils/clipboardNotifs.ts
Normal file
22
src/utils/clipboardNotifs.ts
Normal file
|
@ -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,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import translations from "./translations/index.mjs";
|
import translations from "../translations/index.mjs";
|
||||||
|
|
||||||
export function arrayDiff(
|
export function arrayDiff(
|
||||||
a: string[],
|
a: string[],
|
Loading…
Reference in a new issue