Starting to pull together an SPA structure: a router, page interface and the login page with template.

This commit is contained in:
Herbert Wolverson 2023-04-21 19:40:07 +00:00
parent f03d305dc8
commit 274d1c93ac
3 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,7 @@
export function getValueFromForm(id: string): string {
let input = document.getElementById(id) as HTMLInputElement;
if (input) {
return input.value;
}
return "";
}

View File

@ -0,0 +1,3 @@
export interface Page {
wireup(): void;
}

View File

@ -0,0 +1,41 @@
import { LoginPage } from './login/login';
import { Page } from './page';
export class SiteRouter {
hasCredentials: boolean;
curentPage: Page | undefined;
constructor() {
this.curentPage = undefined;
let token = localStorage.getItem("token");
if (token) {
this.hasCredentials = true;
} else {
this.hasCredentials = false;
}
}
initialRoute() {
if (this.hasCredentials) {
this.goto("dashboard");
} else {
this.goto("login");
}
}
// Handle actual navigation between pages
goto(page: string) {
console.log("Navigate to " + page)
switch (page) {
case "login": {
this.curentPage = new LoginPage();
break;
}
default: {
alert("I don't know how to go to: " + page);
return;
}
}
this.curentPage.wireup();
}
}