From 404de53c756e97fa60ce72e2e2da1d87a3a85443 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 6 Oct 2020 18:06:11 +0200 Subject: [PATCH] basic url router and navigation bootstrapping --- src/main.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.js b/src/main.js index 2e7c80df..05767a34 100644 --- a/src/main.js +++ b/src/main.js @@ -22,8 +22,11 @@ import {SessionContainer} from "./matrix/SessionContainer.js"; import {StorageFactory} from "./matrix/storage/idb/StorageFactory.js"; import {SessionInfoStorage} from "./matrix/sessioninfo/localstorage/SessionInfoStorage.js"; import {BrawlViewModel} from "./domain/BrawlViewModel.js"; +import {Navigation} from "./domain/navigation/Navigation.js"; +import {URLRouter} from "./domain/navigation/URLRouter.js"; import {BrawlView} from "./ui/web/BrawlView.js"; import {Clock} from "./ui/web/dom/Clock.js"; +import {HashObservable} from "./ui/web/dom/HashObservable.js"; import {OnlineStatus} from "./ui/web/dom/OnlineStatus.js"; import {CryptoDriver} from "./ui/web/dom/CryptoDriver.js"; import {WorkerPool} from "./utils/WorkerPool.js"; @@ -115,6 +118,21 @@ export async function main(container, paths, legacyExtras) { workerPromise = loadOlmWorker(paths); } + const navigation = new Navigation(function allowsChild(parent, child) { + const {type} = child; + switch (parent?.type) { + case undefined: + // allowed root segments + return type === "login" || type === "session"; + case "session": + return type === "room" || type === "settings"; + default: + return false; + } + }); + const urlRouter = new URLRouter(new HashObservable(), navigation); + urlRouter.start(); + const vm = new BrawlViewModel({ createSessionContainer: () => { return new SessionContainer({ @@ -132,6 +150,8 @@ export async function main(container, paths, legacyExtras) { sessionInfoStorage, storageFactory, clock, + urlRouter, + navigation }); window.__brawlViewModel = vm; await vm.load();