11import { AsyncPipe } from '@angular/common' ;
22import {
33 Component ,
4+ Inject ,
45 Input ,
56 OnDestroy ,
67 OnInit ,
@@ -29,6 +30,10 @@ import {
2930 take ,
3031} from 'rxjs/operators' ;
3132
33+ import {
34+ APP_CONFIG ,
35+ AppConfig ,
36+ } from '../../../../config/app-config.interface' ;
3237import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths' ;
3338import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths' ;
3439import { BrowseService } from '../../../core/browse/browse.service' ;
@@ -76,6 +81,7 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
7681 subs : Subscription [ ] = [ ] ;
7782
7883 constructor (
84+ @Inject ( APP_CONFIG ) public appConfig : AppConfig ,
7985 public router : Router ,
8086 private browseService : BrowseService ,
8187 ) {
@@ -93,14 +99,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
9399 allOptions . push ( {
94100 id : 'search' ,
95101 label : 'collection.page.browse.search.head' ,
96- routerLink : comColRoute ,
102+ routerLink : ` ${ comColRoute } /search` ,
97103 } ) ;
98104 } else if ( this . contentType === 'community' ) {
99105 comColRoute = getCommunityPageRoute ( this . id ) ;
100106 allOptions . push ( {
101107 id : 'search' ,
102108 label : 'collection.page.browse.search.head' ,
103- routerLink : comColRoute ,
109+ routerLink : ` ${ comColRoute } /search` ,
104110 } ) ;
105111 allOptions . push ( {
106112 id : 'comcols' ,
@@ -114,11 +120,24 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
114120 label : `browse.comcol.by.${ config . id } ` ,
115121 routerLink : `${ comColRoute } /browse/${ config . id } ` ,
116122 } ) ) ) ;
123+
124+ // When the default tab is not the "search" tab, the "search" tab is moved
125+ // at the end of the tabs ribbon for aesthetics purposes.
126+ if ( this . appConfig [ this . contentType ] . defaultBrowseTab !== 'search' ) {
127+ allOptions . push ( allOptions . shift ( ) ) ;
128+ }
117129 }
118130 return allOptions ;
119131 } ) ,
120132 ) ;
121133
134+ let comColRoute : string ;
135+ if ( this . contentType === 'collection' ) {
136+ comColRoute = getCollectionPageRoute ( this . id ) ;
137+ } else if ( this . contentType === 'community' ) {
138+ comColRoute = getCommunityPageRoute ( this . id ) ;
139+ }
140+
122141 this . subs . push ( combineLatest ( [
123142 this . allOptions$ ,
124143 this . router . events . pipe (
@@ -129,11 +148,29 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
129148 ) ,
130149 ] ) . subscribe ( ( [ navOptions , url ] : [ ComColPageNavOption [ ] , string ] ) => {
131150 for ( const option of navOptions ) {
132- if ( option . routerLink === url ?. split ( '?' ) [ 0 ] ) {
151+ if ( url ?. split ( '?' ) [ 0 ] === comColRoute && option . id === this . appConfig [ this . contentType ] . defaultBrowseTab ) {
152+ void this . router . navigate ( [ option . routerLink ] , { queryParams : option . params } ) ;
153+ break ;
154+ } else if ( option . routerLink === url ?. split ( '?' ) [ 0 ] ) {
133155 this . currentOption$ . next ( option ) ;
156+ break ;
134157 }
135158 }
136159 } ) ) ;
160+
161+ if ( this . router . url ?. split ( '?' ) [ 0 ] === comColRoute ) {
162+ this . allOptions$ . pipe (
163+ take ( 1 ) ,
164+ ) . subscribe ( ( allOptions : ComColPageNavOption [ ] ) => {
165+ for ( const option of allOptions ) {
166+ if ( option . id === this . appConfig [ this . contentType ] . defaultBrowseTab ) {
167+ this . currentOption$ . next ( option [ 0 ] ) ;
168+ void this . router . navigate ( [ option . routerLink ] , { queryParams : option . params } ) ;
169+ break ;
170+ }
171+ }
172+ } ) ;
173+ }
137174 }
138175
139176 ngOnDestroy ( ) : void {
0 commit comments