some cleanup

This commit is contained in:
Bruno Windels 2020-10-09 09:56:01 +02:00
parent da9798979c
commit 696e7856f8
4 changed files with 39 additions and 16 deletions

View File

@ -39,6 +39,7 @@ export class BrawlViewModel extends ViewModel {
}
async load() {
// TODO: deduplicate code here
this.track(this.navigation.observe("login").subscribe(shown => {
if (shown) {
this._showLogin();
@ -125,7 +126,7 @@ export class BrawlViewModel extends ViewModel {
sessionContainer.startWithExistingSession(sessionId);
return sessionContainer;
},
sessionCallback: sessionContainer => this._sessionCallback(sessionContainer)
sessionCallback: this._sessionCallback
});
this._sessionLoadViewModel.start();
});

View File

@ -23,7 +23,7 @@ export class URLRouter {
this._navigation = navigation;
}
start() {
attach() {
this._subscription = this._history.subscribe(url => {
this._applyUrl(url);
});
@ -60,6 +60,7 @@ export class URLRouter {
}
replaceUrl(url) {
// TODO: we don't want this to always to trigger an update
this._history.replaceUrl(url);
}

View File

@ -0,0 +1,32 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import {Navigation} from "./Navigation.js";
export function createNavigation() {
return 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 === "rooms" || type === "settings";
default:
return false;
}
});
}

View File

@ -22,7 +22,7 @@ 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 {createNavigation} from "./domain/navigation/index.js";
import {URLRouter} from "./domain/navigation/URLRouter.js";
import {BrawlView} from "./ui/web/BrawlView.js";
import {Clock} from "./ui/web/dom/Clock.js";
@ -118,20 +118,9 @@ 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 navigation = createNavigation();
const urlRouter = new URLRouter(new History(), navigation);
urlRouter.start();
urlRouter.attach();
const vm = new BrawlViewModel({
createSessionContainer: () => {