1
0
Fork 0
VaultUI/src/main.ts

155 lines
3.8 KiB
TypeScript
Raw Normal View History

2021-04-15 13:01:58 +01:00
'use strict';
2021-04-18 11:28:55 +01:00
// JS & CSS
2021-05-10 11:35:14 +01:00
/* eslint-disable */
2021-04-15 13:01:58 +01:00
import "./scss/main.scss";
2021-05-10 12:07:19 +01:00
import UIkit from 'uikit';
import Icons from 'uikit/dist/js/uikit-icons';
2021-05-10 11:35:14 +01:00
// @ts-ignore
2021-04-15 13:01:58 +01:00
UIkit.use(Icons);
2021-05-08 03:28:37 +01:00
import Prism from "prismjs";
2021-05-09 10:08:04 +01:00
import "prismjs/components/prism-json";
2021-04-15 13:01:58 +01:00
Prism.highlightAll();
2021-05-03 09:30:22 +01:00
/* eslint-enable */
2021-04-15 13:01:58 +01:00
import {
changePage,
renderPage,
2021-05-07 23:21:38 +01:00
} from "./pageUtils";
2021-05-09 11:18:18 +01:00
import { getSealStatus } from "./api/sys/getSealStatus";
import { makeElement } from "./htmlUtils";
2021-05-08 03:28:37 +01:00
import { pageState } from "./globalPageState";
import { playground } from "./playground";
2021-04-15 13:01:58 +01:00
2021-04-18 11:28:55 +01:00
// Translations
2021-05-08 03:28:37 +01:00
import { Page } from "./types/Page";
2021-05-08 00:58:28 +01:00
import { formatDistance } from './formatDistance';
2021-04-18 11:28:55 +01:00
import i18next from 'i18next';
2021-05-08 03:28:37 +01:00
// @ts-ignore
import translations from './translations/index.mjs'
2021-04-18 11:28:55 +01:00
2021-05-10 11:35:14 +01:00
function ListItem(children: Element[] | Element): HTMLElement {
2021-04-17 10:56:44 +01:00
return makeElement({
tag: "li",
children: children
});
}
2021-05-10 11:35:14 +01:00
declare global {
interface Window { pageContent: Element; }
}
function onLoad(): void {
2021-04-17 10:56:44 +01:00
document.body.innerHTML = "";
document.body.appendChild(makeElement({
tag: "nav",
class: ["uk-navbar", "uk-navbar-container"],
2021-04-18 11:28:55 +01:00
children: [
makeElement({
2021-04-18 11:28:55 +01:00
tag: "div",
class: "uk-navbar-left",
children: makeElement({
tag: "ul",
class: "uk-navbar-nav",
children: [
ListItem(makeElement({
tag: "a",
text: i18next.t("home_btn"),
2021-05-10 11:35:14 +01:00
onclick: () => { changePage("HOME"); }
2021-04-18 11:28:55 +01:00
})),
ListItem(makeElement({
tag: "a",
text: i18next.t("back_btn"),
2021-05-10 11:35:14 +01:00
onclick: () => { (pageState.currentPage as Page).goBack(); }
2021-04-18 11:28:55 +01:00
})),
ListItem(makeElement({
tag: "a",
text: i18next.t("refresh_btn"),
2021-05-10 11:35:14 +01:00
onclick: () => { changePage(pageState.currentPageString); }
2021-04-18 11:28:55 +01:00
})),
]
})
}),
makeElement({
tag: "div",
class: "uk-navbar-right",
children: makeElement({
tag: "ul",
class: "uk-navbar-nav",
children: [
ListItem(makeElement({
tag: "a",
2021-04-18 11:52:24 +01:00
text: i18next.t("me_btn"),
2021-05-10 11:35:14 +01:00
onclick: () => { changePage("ME"); }
2021-04-18 11:28:55 +01:00
}))
]
})
})
2021-04-18 11:28:55 +01:00
]
2021-04-17 10:56:44 +01:00
}));
document.body.appendChild(makeElement({
tag: "div",
class: ["uk-container", "uk-container-medium", "uk-align-center"],
children: makeElement({
tag: "div",
class: ["uk-card", "uk-card-body"],
children: [
makeElement({
tag: "h3",
class: "uk-card-title",
id: "pageTitle",
2021-04-18 11:52:24 +01:00
text: ""
2021-04-17 10:56:44 +01:00
}),
makeElement({
tag: "div",
id: "pageContent"
})
]
})
}));
2021-05-10 11:35:14 +01:00
window.pageContent = document.querySelector("#pageContent");
if (process.env.NODE_ENV == "development") {
2021-05-10 11:35:14 +01:00
playground();
}
2021-04-15 13:01:58 +01:00
renderPage();
2021-05-10 11:35:14 +01:00
setInterval(() => {
2021-04-19 20:17:07 +01:00
if (pageState.currentPageString != "UNSEAL") {
if (pageState.apiURL.length != 0) { return; }
2021-05-10 11:35:14 +01:00
void getSealStatus().then((sealStatus) => {
if (sealStatus.sealed) {
changePage("UNSEAL");
return;
}
});
2021-04-15 13:01:58 +01:00
}
}, 5000);
2021-04-24 16:26:31 +01:00
}
2021-04-18 11:28:55 +01:00
2021-05-10 11:35:14 +01:00
document.addEventListener('DOMContentLoaded', function () {
2021-05-09 16:31:01 +01:00
console.log("Loading...");
// @ts-expect-error
2021-05-09 16:31:01 +01:00
console.log("Build Data:", BUILD_STRING);
2021-05-10 11:35:14 +01:00
void i18next.init({
lng: pageState.language,
2021-04-19 19:45:51 +01:00
fallbackLng: 'en',
2021-04-18 11:28:55 +01:00
debug: true,
2021-05-08 03:28:37 +01:00
// @ts-ignore
resources: Object.fromEntries(Object.entries(translations).map(([k, v]) => [k, { translation: v }])),
2021-04-18 11:52:24 +01:00
interpolation: {
2021-05-10 11:35:14 +01:00
format: function (value: unknown, format, _): string {
2021-04-18 11:52:24 +01:00
if (format === 'until_date' && value instanceof Date) return formatDistance(new Date(), new Date(value));
2021-05-10 11:35:14 +01:00
return value as string;
2021-04-18 11:52:24 +01:00
}
2021-04-18 11:28:55 +01:00
}
2021-05-10 11:35:14 +01:00
}).then(function (_) {
onLoad();
2021-04-18 11:28:55 +01:00
});
2021-04-18 13:18:14 +01:00
}, false);