Start work on handling invalid URLs

This commit is contained in:
Danila Fedorin 2021-08-30 11:01:56 -07:00
parent 88116bdfa6
commit 878663ca07

View file

@ -36,19 +36,12 @@ export class RootViewModel extends ViewModel {
} }
_updateChildVMs(oldLink) { _updateChildVMs(oldLink) {
if (this.link) {
this.createLinkViewModel = null;
if (!oldLink || !oldLink.equals(this.link)) { if (!oldLink || !oldLink.equals(this.link)) {
this.openLinkViewModel = new OpenLinkViewModel(this.childOptions({ this.openLinkViewModel = new OpenLinkViewModel(this.childOptions({
link: this.link, link: this.link,
clients: createClients(), clients: createClients(),
})); }));
} }
} else {
this.openLinkViewModel = null;
this.createLinkViewModel = new CreateLinkViewModel(this.childOptions());
}
this.emitChange();
} }
_hideLinks() { _hideLinks() {
@ -58,24 +51,30 @@ export class RootViewModel extends ViewModel {
} }
updateHash(hash) { updateHash(hash) {
// All view models except openLink are re-created anyway.
// Might as well clear them to avoid having to
// manually reset (n-1)/n view models in every case.
const oldLink = this.link;
this.link = null;
this.showDisclaimer = false; this.showDisclaimer = false;
this.loadServerPolicyViewModel = null;
this.createLinkViewModel = null;
if (hash.startsWith("#/policy/")) { if (hash.startsWith("#/policy/")) {
const server = hash.substr(9); const server = hash.substr(9);
this._hideLinks(); this.openLinkViewModel = null;
this.loadServerPolicyViewModel = new LoadServerPolicyViewModel(this.childOptions({server})); this.loadServerPolicyViewModel = new LoadServerPolicyViewModel(this.childOptions({server}));
this.loadServerPolicyViewModel.load(); this.loadServerPolicyViewModel.load();
this.emitChange();
} else if (hash.startsWith("#/disclaimer/")) { } else if (hash.startsWith("#/disclaimer/")) {
this._hideLinks(); this.openLinkViewModel = null;
this.loadServerPolicyViewModel = null;
this.showDisclaimer = true; this.showDisclaimer = true;
this.emitChange(); } else if (hash === "" || hash === "#" || hash === "#/") {
} else { this.openLinkViewModel = null;
const oldLink = this.link; this.createLinkViewModel = new CreateLinkViewModel(this.childOptions());
this.loadServerPolicyViewModel = null; } else if (this.link = Link.parse(hash)) {
this.link = Link.parse(hash); this.link = Link.parse(hash);
this._updateChildVMs(oldLink); this._updateChildVMs(oldLink);
} }
this.emitChange();
} }
clearPreferences() { clearPreferences() {