mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
rewrote header reaction to route change as ngrx event
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Component, OnInit, OnDestroy, HostListener } from "@angular/core";
|
||||
import { Router, NavigationEnd, Event } from "@angular/router";
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Store } from "@ngrx/store";
|
||||
import { HeaderState } from "./header.reducer";
|
||||
import { HeaderActions } from "./header.actions";
|
||||
@@ -10,32 +9,19 @@ import { Observable } from "rxjs";
|
||||
styleUrls: ['header.component.css'],
|
||||
templateUrl: 'header.component.html'
|
||||
})
|
||||
export class HeaderComponent implements OnDestroy, OnInit {
|
||||
private routerSubscription: any;
|
||||
export class HeaderComponent implements OnInit {
|
||||
public isNavBarCollapsed: Observable<boolean>;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private store: Store<HeaderState>
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.routerSubscription = this.router.events.subscribe((event: Event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
this.collapse();
|
||||
}
|
||||
});
|
||||
this.isNavBarCollapsed = this.store.select('headerReducer')
|
||||
.map(({ navCollapsed }: HeaderState) => navCollapsed);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.routerSubscription) {
|
||||
this.routerSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
private collapse(): void {
|
||||
this.store.dispatch(HeaderActions.collapse());
|
||||
}
|
||||
|
Reference in New Issue
Block a user