Skip to content

Commit

Permalink
[DURACOM-195] Base components (simplify header-navbar-wrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-negretti committed Nov 24, 2023
1 parent 9132bc0 commit da5ddac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div [ngClass]="{'open': !(isNavBarCollapsed | async)}" id="header-navbar-wrapper">
<div [ngClass]="{'open': !(isNavBarCollapsed$ | async)}" id="header-navbar-wrapper">
<ds-themed-header></ds-themed-header>
<ds-themed-navbar></ds-themed-navbar>
</div>
22 changes: 5 additions & 17 deletions src/app/header-nav-wrapper/header-navbar-wrapper.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState } from '../app.reducer';
import { hasValue } from '../shared/empty.util';
import { Observable, Subscription } from 'rxjs';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { MenuService } from '../shared/menu/menu.service';
import { MenuID } from '../shared/menu/menu-id.model';
import { HostWindowService, WidthCategory } from '../shared/host-window.service';
Expand All @@ -15,31 +12,22 @@ import { HostWindowService, WidthCategory } from '../shared/host-window.service'
styleUrls: ['header-navbar-wrapper.component.scss'],
templateUrl: 'header-navbar-wrapper.component.html',
})
export class HeaderNavbarWrapperComponent implements OnInit, OnDestroy {
@HostBinding('class.open') isOpen = false;
private sub: Subscription;
public isNavBarCollapsed: Observable<boolean>;
export class HeaderNavbarWrapperComponent implements OnInit {
public isNavBarCollapsed$: Observable<boolean>;
public isMobile$: Observable<boolean>;

menuID = MenuID.PUBLIC;
maxMobileWidth = WidthCategory.SM;

constructor(
private store: Store<AppState>,
private menuService: MenuService,
protected windowService: HostWindowService,
) {
}

ngOnInit(): void {
this.isMobile$ = this.windowService.isUpTo(this.maxMobileWidth);
this.isNavBarCollapsed = this.menuService.isMenuCollapsed(this.menuID);
this.sub = this.isNavBarCollapsed.subscribe((isCollapsed) => this.isOpen = !isCollapsed);
this.isNavBarCollapsed$ = this.menuService.isMenuCollapsed(this.menuID);
}

ngOnDestroy() {
if (hasValue(this.sub)) {
this.sub.unsubscribe();
}
}
}

0 comments on commit da5ddac

Please sign in to comment.