1
0
Fork 0

Add nix shell, move pagerouter into this repo, update packages.

This commit is contained in:
ChaotiCryptidz - 2021-11-21 10:51:12 +00:00
parent a256e7c734
commit 0239a619e7
12 changed files with 169 additions and 47 deletions

5
nix.shell Normal file
View file

@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
packages = with pkgs; [
nodejs
];
}

View file

@ -1,50 +1,50 @@
{
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.4",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.14.2",
"@babel/plugin-proposal-object-rest-spread": "^7.14.4",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@types/file-saver": "^2.0.2",
"@types/prismjs": "^1.16.5",
"@types/uikit": "^3.3.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"babel-loader": "^8.2.2",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-decorators": "^7.16.4",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4",
"@types/file-saver": "^2.0.4",
"@types/prismjs": "^1.16.6",
"@types/uikit": "^3.3.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"babel-loader": "^8.2.3",
"clipboard": "^2.0.8",
"codejar": "^3.4.0",
"core-js": "^3.13.1",
"css-loader": "^5.2.6",
"date-fns": "^2.22.1",
"eslint": "^7.27.0",
"codejar": "^3.5.0",
"core-js": "^3.19.1",
"css-loader": "^6.5.1",
"date-fns": "^2.26.0",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"file-saver": "^2.0.5",
"git-revision-webpack-plugin": "^5.0.0",
"html-webpack-plugin": "^5.3.1",
"i18next": "^20.3.1",
"mini-css-extract-plugin": "^2.0.0",
"node-sass": "^6.0.0",
"html-webpack-plugin": "^5.5.0",
"i18next": "^21.5.2",
"mini-css-extract-plugin": "^2.4.5",
"node-sass": "^6.0.1",
"normalize.css": "^8.0.1",
"preact": "^10.5.13",
"prettier": "^2.3.0",
"prismjs": "^1.23.0",
"qr-scanner": "^1.2.0",
"preact": "^10.5.15",
"prettier": "^2.4.1",
"prismjs": "^1.25.0",
"qr-scanner": "^1.3.0",
"raw-loader": "^4.0.2",
"sass-loader": "^12.1.0",
"ts-loader": "^9.2.2",
"typescript": "^4.3.2",
"uikit": "^3.6.22",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2",
"z-pagerouter": "^1.0.6"
"sass-loader": "^12.3.0",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
"uikit": "^3.9.3",
"webpack": "^5.64.2",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.5.0"
},
"dependencies": {
"css-minimizer-webpack-plugin": "^3.0.0"
"css-minimizer-webpack-plugin": "^3.1.4",
"npm-update": "^2.1.0"
}
}

View file

@ -1,7 +1,4 @@
// So that we dont get `PageType not found in 'z-pagerouter' import/named`
/* eslint-disable */
import { PageType } from "z-pagerouter";
/* eslint-enable */
import { PageType } from "./pagerouter/PageType";
import { AccessHomePage } from "./pages/Access/AccessHome";
import { AuthHomePage } from "./pages/Access/Auth/AuthHome";

View file

@ -1,5 +1,5 @@
import { JSX, render } from "preact";
import { PageRouter } from "z-pagerouter";
import { PageRouter } from "../pagerouter/PageRouter";
import i18next from "i18next";
export type NavBarProps = {

View file

@ -22,7 +22,7 @@ Prism.highlightAll();
import translations from "./translations/index.mjs";
// Actual Imports
import { PageRouter } from "z-pagerouter";
import { PageRouter } from "./pagerouter/PageRouter";
import { formatDistance } from "./formatDistance";
import { getSealStatus } from "./api/sys/getSealStatus";
import { pageList } from "./allPages";

View file

@ -1,4 +1,4 @@
import { PageRouter } from "z-pagerouter";
import { PageRouter } from "./pagerouter/PageRouter";
import { PageState } from "./state/PageState";
import { getSealStatus } from "./api/sys/getSealStatus";
import { lookupSelf } from "./api/sys/lookupSelf";

View file

@ -0,0 +1,6 @@
import { PageType } from "./PageType";
export type PageListType = {
getPageIDs(): Promise<string[]>;
getPage(pageID: string): Promise<PageType>;
}

View file

@ -0,0 +1,105 @@
import { PageType } from "./PageType";
import { PageListType } from "./PageListType";
const PageDoesNotExistError = new Error("Page does not exist.");
const PageHasNotBeenSetError = new Error("Page has not been set.");
export type Options = {
pageList: PageListType;
state: unknown;
pageContentElement: HTMLElement;
pageTitleElement: HTMLElement;
resetElementContent?: Boolean;
onPageChange: () => void;
}
export class PageRouter {
constructor(
options: Options
) {
this.pageList = options.pageList;
this.state = options.state;
this.pageContentElement = options.pageContentElement;
this.pageTitleElement = options.pageTitleElement;
this.resetElementContent = (options.resetElementContent || true) == true;
this.onPageChange = (options.onPageChange);
}
public onPageChange: () => void;
private pageList: PageListType;
private currentPageID: string;
private currentPage: PageType;
private resetElementContent: Boolean;
public state: unknown;
public pageContentElement: HTMLElement;
public pageTitleElement: HTMLElement;
public async getPageIDs(): Promise<string[]> {
return await this.pageList.getPageIDs();
}
public async getCurrentPage(): Promise<PageType> {
return this.currentPage;
}
public async getCurrentPageID(): Promise<string> {
return this.currentPageID;
}
public async setPageContent(content: string | HTMLElement): Promise<void> {
if (typeof content === "string") {
this.pageContentElement.innerHTML = content;
} else {
this.pageContentElement.innerHTML = "";
this.pageContentElement.appendChild(content);
}
}
public async changePage(pageID: string): Promise<void> {
if (!(await this.getPageIDs()).includes(pageID)) throw PageDoesNotExistError;
// Do cleanup on current page.
if (this.currentPage) {
await this.currentPage.cleanup();
}
// Set the current page to the new page
this.currentPageID = pageID;
this.currentPage = await this.pageList.getPage(pageID);
await this.currentPage.setRouterAndState(this, this.state);
// Dispatch an event saying the page has been changed.
this.onPageChange();
// Render the page.
await this.renderPage();
}
public async renderPage(): Promise<void> {
if (!this.currentPage) throw PageHasNotBeenSetError;
if (this.resetElementContent) {
// Reset back to blank.
this.pageContentElement.innerHTML = "";
this.pageTitleElement.innerHTML = "";
}
await Promise.all([
this.currentPage.renderPageTitle(),
this.currentPage.render(),
])
;
}
public async refresh(): Promise<void> {
await this.renderPage();
}
public async goBack(): Promise<void> {
if (!this.currentPage) throw PageHasNotBeenSetError;
await this.currentPage.goBack();
}
}

View file

@ -0,0 +1,9 @@
import { PageRouter } from "./PageRouter";
export type PageType = {
render(): Promise<void>;
renderPageTitle(): Promise<void>;
goBack(): Promise<void>;
cleanup(): Promise<void>;
setRouterAndState(router: PageRouter, state: unknown): Promise<void>;
}

View file

@ -1,4 +1,4 @@
import { PageRouter } from "z-pagerouter";
import { PageRouter } from "./pagerouter/PageRouter";
import { PageState } from "./state/PageState";
import i18next from "i18next";

View file

@ -1,4 +1,4 @@
import { PageRouter } from "z-pagerouter";
import { PageRouter } from "../pagerouter/PageRouter";
import { PageState } from "../state/PageState";
export class Page {

View file

@ -30,7 +30,7 @@ module.exports = {
})
],
devServer: {
open: process.env.BROWSER || "microsoft-edge-dev",
open: process.env.BROWSER,
},
resolve: {
modules: ['node_modules'],