import { Component , ComponentFactoryResolver , ViewChild , HostListener , AfterViewInit , } from '@angular/core' ; import { Storage } from '../../../services/storage' ; import { Sidebar } from '../../../services/ui/sidebar' ; import { Session } from '../../../services/session' ; import { DynamicHostDirective } from '../../directives/dynamic-host.directive' ; import { GroupsSidebarMarkersComponent } from '../../../modules/groups/sidebar-markers/sidebar-markers.component' ; import { SidebarMarkersService } from './markers.service' ; @ Component ( { selector : 'm-sidebar--markers' , templateUrl : 'markers.component.html' , } ) export class SidebarMarkersComponent implements AfterViewInit { @ ViewChild ( DynamicHostDirective , { static : true } ) host : DynamicHostDirective ; showMarkerSidebar = false ; componentRef ; componentInstance : GroupsSidebarMarkersComponent ; visible : boolean = true ; constructor ( public session , public storage , public sidebar , private sidebarMarkersService , private _componentFactoryResolver ) { this . sidebarMarkersService . setContainer ( this ) ; } ngAfterViewInit ( ) { const isLoggedIn = this . session . isLoggedIn ( ( is ) => { this . checkSidebarVisibility ( is ) ; } ) ; this . checkSidebarVisibility ( isLoggedIn ) ; } checkSidebarVisibility ( isLoggedIn ) { const showMarkerSidebar = isLoggedIn ; if ( showMarkerSidebar === this . showMarkerSidebar ) { return ; } if ( showMarkerSidebar ) { this . createGroupsSideBar ( ) ; } else { this . host . viewContainerRef . clear ( ) ; } this . showMarkerSidebar = showMarkerSidebar ; } createGroupsSideBar ( ) { const componentFactory = this . _componentFactoryResolver . resolveComponentFactory ( GroupsSidebarMarkersComponent ) , viewContainerRef = this . host . viewContainerRef ; this . componentRef = viewContainerRef . createComponent ( componentFactory ) ; this . componentInstance = this . componentRef . instance ; } }