From c95703131729a8ef4449b522473d901e8c9990b1 Mon Sep 17 00:00:00 2001 From: "L. Henze" Date: Tue, 8 Oct 2019 12:32:40 -0400 Subject: [PATCH] from @art-lowel: Observable for currentOptionId Next in order to know what page we're on, I use the route.url observable angular provides us that contains the current url, pipe that through a filter to ensure it has a value for the map below, which will just get the last part of the current url, so the community or collection id, or the type of the browse page. --- .../comcol-page-browse-by.component.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts b/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts index 5a3172436a..8174129d3f 100644 --- a/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts +++ b/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts @@ -1,10 +1,13 @@ -import { Component, Inject, Input, OnInit } from '@angular/core'; +import { Component, Inject, Input, NgZone, OnDestroy, OnInit } from '@angular/core'; +import { Observable } from 'rxjs/internal/Observable'; +import { Subscription } from 'rxjs/internal/Subscription'; import { filter, map, startWith, tap } from 'rxjs/operators'; import { getCollectionPageRoute } from '../../+collection-page/collection-page-routing.module'; import { getCommunityPageRoute } from '../../+community-page/community-page-routing.module'; import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; -import { Router, ActivatedRoute, RouterModule } from '@angular/router'; +import { Router, ActivatedRoute, RouterModule, UrlSegment } from '@angular/router'; import { BrowseByTypeConfig } from '../../../config/browse-by-type-config.interface'; +import { hasValue } from '../empty.util'; export interface ComColPageNavOption { id: string; @@ -34,7 +37,9 @@ export class ComcolPageBrowseByComponent implements OnInit { allOptions: ComColPageNavOption[]; - constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig, private router: Router) { + currentOptionId$: Observable; + + constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig, private route: ActivatedRoute, private router: Router) { } ngOnInit(): void { @@ -59,7 +64,10 @@ export class ComcolPageBrowseByComponent implements OnInit { routerLink: getCommunityPageRoute(this.id) }, ...this.allOptions ]; } - + this.currentOptionId$ = this.route.url.pipe( + filter((urlSegments: UrlSegment[]) => hasValue(urlSegments)), + map((urlSegments: UrlSegment[]) => urlSegments[urlSegments.length - 1].path) + ); } onSelectChange(target) { const optionIndex = target.selectedIndex;