import { Component , OnDestroy } from '@angular/core' ; import { RoutingService , AuthService } from '@spartacus/core' ; import { ModalService , ModalRef } from '@spartacus/storefront' ; import { take } from 'rxjs/operators' ; import { DvntModalSearchComponent } from 'src/app/features/dvnt-modal-search/dvnt-modal-search.component' ; import { DvntProfileLinkListComponent } from 'src/app/features/dvnt-profile-link-list/dvnt-profile-link-list.component' ; import { DvntModalCategoriesComponent } from '../dvnt-modal-categories/dvnt-modal-categories.component' ; import { DvntCartModalComponent } from '../dvnt-cart/dvnt-cart-modal/dvnt-cart-modal.component' ; @ Component ( { selector : 'app-dvnt-bottom-navigation' , templateUrl : './dvnt-bottom-navigation.component.html' , styleUrls : [ './dvnt-bottom-navigation.component.scss' ] , } ) export class DvntBottomNavigationComponent implements OnDestroy { private modalRef : ModalRef ; constructor ( private authService , private routingService , private modalService ) { } ngOnDestroy ( ) { this . clearModalRef ( ) ; } public navigateTo ( path , event ) { this . preventOtherActions ( event ) ; this . routingService . goByUrl ( path ) ; } public setSearchAction ( event ) { this . preventOtherActions ( event ) ; this . createSearchModal ( ) ; } public setCategoriesAction ( event ) { this . preventOtherActions ( event ) ; this . createCategoriesModal ( ) ; } public setCartAction ( event ) { this . preventOtherActions ( event ) ; this . createCartModal ( ) ; } public setProfileAction ( event ) { this . preventOtherActions ( event ) ; this . authService . isUserLoggedIn ( ) . pipe ( take ( 1 ) ) . subscribe ( ( isLogged ) => { isLogged ? this . createProfileModal ( ) : this . routingService . goByUrl ( 'login' ) ; } , ( ) => { } ) ; } private createProfileModal ( ) { this . createModal ( DvntProfileLinkListComponent , 'profile' ) ; } private createSearchModal ( ) { this . createModal ( DvntModalSearchComponent , 'search' ) ; } private createCategoriesModal ( ) { this . createModal ( DvntModalCategoriesComponent , 'categories' ) ; } private createCartModal ( ) { this . createModal ( DvntCartModalComponent , 'cart' ) ; } private createModal ( component , componentType ) { this . clearModalRef ( ) ; this . createModelInstance ( component , componentType ) ; } private createModelInstance ( component , componentType ) { let modalInstance ; this . modalRef = this . modalService . open ( component , { windowClass : 'side-modal slide-from-left' , backdropClass : 'side-modal-backdrop' , } ) ; modalInstance = this . modalRef . componentInstance ; modalInstance . type = componentType ; } private preventOtherActions ( event ) { event . stopPropagation ( ) ; event . preventDefault ( ) ; } private clearModalRef ( ) { if ( this . modalRef ) { this . modalService . dismissActiveModal ( ) ; this . modalRef . dismiss ( ) ; this . modalRef = null ; } } }