From c6e3806024e4c42a6ad18c143b6cc46b995088ed Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Mon, 14 Oct 2019 16:40:27 -0400 Subject: [PATCH] [M] Move history stuff to navigation.ts --- src/components/app/app.ts | 14 ------------- src/components/navigation/navigation.ts | 26 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/components/app/app.ts b/src/components/app/app.ts index 3daa71d..3c2c458 100644 --- a/src/components/app/app.ts +++ b/src/components/app/app.ts @@ -98,20 +98,6 @@ export default class App extends Vue { // Show splash console.log(Constants.SPLASH); - - // Set history state (TODO: Dynamically detect initial url - window.history.replaceState({lastTab: 'overall'}, '', '/overall'); - - // Create history state listener - window.onpopstate = e => - { - if (e.state) - { - // Restore previous tab - console.log(`onPopState: Current: ${this.selectedTab}, Previous: ${e.state.lastTab}`); - this.selectedTab = e.state.lastTab; - } - }; } /** diff --git a/src/components/navigation/navigation.ts b/src/components/navigation/navigation.ts index 6678b27..95098b2 100644 --- a/src/components/navigation/navigation.ts +++ b/src/components/navigation/navigation.ts @@ -9,10 +9,34 @@ import Constants from '@/constants'; }) export default class Navigation extends Vue { - public activeIndex: string = 'overall'; + // @ts-ignore + @Prop() activeIndex: string; @Prop() courses: any; + /** + * This is called when the instance is created. + */ + public created() + { + // Show splash TODO: Remove + console.log('Created Navigation'); + + // Set history state (TODO: Dynamically detect initial url + window.history.replaceState({lastTab: 'overall'}, '', '/overall'); + + // Create history state listener + window.onpopstate = e => + { + if (e.state) + { + // Restore previous tab + console.log(`onPopState: Current: ${this.activeIndex}, Previous: ${e.state.lastTab}`); + this.activeIndex = e.state.lastTab; + } + }; + } + /** * This function is called when the selection changes. *