1
0
Fork 0
VaultUI/src/main.ts

132 lines
3.3 KiB
TypeScript
Raw Normal View History

"use strict";
2021-04-15 13:01:58 +01:00
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';
// Don't Sort These!
2021-05-10 12:07:19 +01:00
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";
// Don't Sort These!
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
// Actual Imports
import { NavBar } from "./elements/NavBar";
import { PageRouter } from "./PageSystem/PageRouter";
import { allPages } from "./allPages";
import { formatDistance } from "./formatDistance";
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";
import i18next from "i18next";
2021-05-08 03:28:37 +01:00
// @ts-ignore
import translations from "./translations/index.mjs";
2021-04-17 10:56:44 +01:00
2021-05-10 11:35:14 +01:00
declare global {
interface Window {
pageContent: Element;
}
2021-05-10 11:35:14 +01:00
}
2021-05-12 17:37:09 +01:00
async function onLoad(): Promise<void> {
2021-04-17 10:56:44 +01:00
document.body.innerHTML = "";
2021-05-15 10:56:08 +01:00
document.body.appendChild(makeElement({ tag: "div", id: "navBarReplace" }));
document.body.appendChild(
makeElement({
2021-04-17 10:56:44 +01:00
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",
text: "",
}),
makeElement({
tag: "div",
id: "pageContent",
}),
],
}),
}),
);
2021-04-17 10:56:44 +01:00
2021-05-10 11:35:14 +01:00
window.pageContent = document.querySelector("#pageContent");
const pageRouter = new PageRouter(
allPages,
pageState,
document.getElementById("pageContent"),
document.getElementById("pageTitle"),
);
document.querySelector("#navBarReplace").replaceWith(NavBar(pageRouter));
pageRouter.addEventListener("pageChanged", async function (_) {
pageState.currentPage = await pageRouter.getCurrentPageID();
document.documentElement.dir = pageState.pageDirection;
});
if (process.env.NODE_ENV == "development") {
await playground(pageRouter);
}
await pageRouter.changePage(pageState.currentPageString);
2021-04-15 13:01:58 +01:00
setInterval(async () => {
if ((await pageRouter.getCurrentPageID()) != "UNSEAL") {
if (pageState.apiURL.length != 0) {
return;
}
const sealStatus = await getSealStatus();
if (sealStatus.sealed) {
await pageRouter.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
document.addEventListener(
"DOMContentLoaded",
function () {
console.log("Loading...");
// @ts-expect-error
console.log("Build Data:", BUILD_STRING);
void i18next
.init({
lng: pageState.language,
fallbackLng: "en",
debug: true,
// @ts-ignore
resources: Object.fromEntries(
Object.entries(translations).map(([k, v]) => [k, { translation: v }]),
),
interpolation: {
format: function (value: unknown, format, _): string {
if (format === "until_date" && value instanceof Date)
2021-05-15 10:58:54 +01:00
return formatDistance(new Date(), new Date(value), pageState.language);
return value as string;
},
},
})
.then(function (_) {
2021-05-12 17:37:09 +01:00
void onLoad();
});
},
false,
);