11import { BehaviorSubject , combineLatest as observableCombineLatest , Observable , Subscription , of as observableOf } from 'rxjs' ;
2- import { Component , Inject , OnInit , OnDestroy , Input , OnChanges } from '@angular/core' ;
2+ import { Component , Inject , OnInit , OnDestroy , Input , OnChanges , SimpleChanges } from '@angular/core' ;
33import { RemoteData } from '../../core/data/remote-data' ;
44import { PaginatedList } from '../../core/data/paginated-list.model' ;
55import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model' ;
@@ -14,7 +14,7 @@ import { getFirstSucceededRemoteData } from '../../core/shared/operators';
1414import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service' ;
1515import { StartsWithType } from '../../shared/starts-with/starts-with-decorator' ;
1616import { PaginationService } from '../../core/pagination/pagination.service' ;
17- import { map } from 'rxjs/operators' ;
17+ import { map , distinctUntilChanged } from 'rxjs/operators' ;
1818import { APP_CONFIG , AppConfig } from '../../../config/app-config.interface' ;
1919import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
2020import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator' ;
@@ -158,15 +158,22 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
158158 ngOnInit ( ) : void {
159159
160160 const sortConfig = new SortOptions ( 'default' , SortDirection . ASC ) ;
161- this . updatePage ( getBrowseSearchOptions ( this . defaultBrowseId , this . paginationConfig , sortConfig ) ) ;
162161 this . currentPagination$ = this . paginationService . getCurrentPagination ( this . paginationConfig . id , this . paginationConfig ) ;
163162 this . currentSort$ = this . paginationService . getCurrentSort ( this . paginationConfig . id , sortConfig ) ;
163+ const routeParams$ : Observable < Params > = observableCombineLatest ( [
164+ this . route . params ,
165+ this . route . queryParams ,
166+ ] ) . pipe (
167+ map ( ( [ params , queryParams ] : [ Params , Params ] ) => Object . assign ( { } , params , queryParams ) ) ,
168+ distinctUntilChanged ( ( prev : Params , curr : Params ) => prev . id === curr . id && prev . authority === curr . authority && prev . value === curr . value && prev . startsWith === curr . startsWith ) ,
169+ ) ;
164170 this . subs . push (
165- observableCombineLatest ( [ this . route . params , this . route . queryParams , this . scope$ , this . currentPagination$ , this . currentSort$ ] ) . pipe (
166- map ( ( [ routeParams , queryParams , scope , currentPage , currentSort ] ) => {
167- return [ Object . assign ( { } , routeParams , queryParams ) , scope , currentPage , currentSort ] ;
168- } )
169- ) . subscribe ( ( [ params , scope , currentPage , currentSort ] : [ Params , string , PaginationComponentOptions , SortOptions ] ) => {
171+ observableCombineLatest ( [
172+ routeParams$ ,
173+ this . scope$ ,
174+ this . currentPagination$ ,
175+ this . currentSort$ ,
176+ ] ) . subscribe ( ( [ params , scope , currentPage , currentSort ] : [ Params , string , PaginationComponentOptions , SortOptions ] ) => {
170177 this . browseId = params . id || this . defaultBrowseId ;
171178 this . authority = params . authority ;
172179
@@ -190,8 +197,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
190197
191198 }
192199
193- ngOnChanges ( ) : void {
194- this . scope$ . next ( this . scope ) ;
200+ ngOnChanges ( changes : SimpleChanges ) : void {
201+ if ( hasValue ( changes . scope ) ) {
202+ this . scope$ . next ( this . scope ) ;
203+ }
195204 }
196205
197206 /**
0 commit comments