From 4d7b41bf2a28fa20c016f5b6eb6222b98e4b81f1 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 21 Dec 2019 11:52:16 -0500 Subject: [PATCH] [+] Create constructor --- src/logic/navigator.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/logic/navigator.ts b/src/logic/navigator.ts index fcc5c6c..cd8ffbb 100644 --- a/src/logic/navigator.ts +++ b/src/logic/navigator.ts @@ -11,6 +11,30 @@ export default class Navigator private activeIndex: Index; private updateCallback?: () => void; + constructor() + { + // Set history state + let url = '/' + window.location.hash; + if (url == '/' || url == '') url = '/#overall'; + window.history.replaceState({lastTab: url.substring(1)}, '', url); + + // Update initial index after loading is done + // TODO: Test this + //pWaitFor(() => this.courses.length > 1 && App.instance.loading != '').then(() => + this.updateIndex(url.substring(2), false); + + // Create history state listener + window.onpopstate = (e: any) => + { + if (e.state) + { + // Restore previous tab + console.log(`onPopState: Current: ${this.activeIndex}, Previous: ${e.state.lastTab}`); + this.updateIndex(e.state.lastTab, false); + } + }; + } + /** * Update index *