- this.router.events.subscribe(
- e => {
- // User clicked on a link in the menu, change the page
- if (e instanceof GuardsCheckStart && this.screenService.isInSmallView()) {
- this.isMenuDisplayed = false
- }
+ this.initRouteEvents()
+ this.injectJS()
+ this.injectCSS()
+
+ this.initHotkeys()
+
+ fromEvent(window, 'resize')
+ .pipe(debounceTime(200))
+ .subscribe(() => this.onResize())
+ }
+
+ isUserLoggedIn () {
+ return this.authService.isLoggedIn()
+ }
+
+ toggleMenu () {
+ this.isMenuDisplayed = !this.isMenuDisplayed
+ this.isMenuChangedByUser = true
+ }
+
+ onResize () {
+ this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser
+ }
+
+ private initRouteEvents () {
+ let resetScroll = true
+ const eventsObs = this.router.events
+
+ const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
+ const navigationEndEvent = eventsObs.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd))
+
+ scrollEvent.subscribe(e => {
+ if (e.position) {
+ return this.viewportScroller.scrollToPosition(e.position)
+ }
+
+ if (e.anchor) {
+ return this.viewportScroller.scrollToAnchor(e.anchor)
+ }
+
+ if (resetScroll) {
+ return this.viewportScroller.scrollToPosition([ 0, 0 ])