11import { ChangeDetectionStrategy , Component , Inject , InjectionToken , OnInit } from '@angular/core' ;
22
33import { Observable } from 'rxjs' ;
4- import { take } from 'rxjs/operators' ;
4+ import { take , tap } from 'rxjs/operators' ;
55
66import { SearchService } from '../core/shared/search/search.service' ;
77import { MyDSpaceResponseParsingService } from '../core/data/mydspace-response-parsing.service' ;
@@ -12,6 +12,10 @@ import { ViewMode } from '../core/shared/view-mode.model';
1212import { MyDSpaceRequest } from '../core/data/request.models' ;
1313import { Context } from '../core/shared/context.model' ;
1414import { RoleType } from '../core/roles/role-types' ;
15+ import { Router } from '@angular/router' ;
16+ import { SearchResult } from '../shared/search/models/search-result.model' ;
17+ import { DSpaceObject } from '../core/shared/dspace-object.model' ;
18+ import { RequestService } from '../core/data/request.service' ;
1519import { MyDSpaceConfigurationValueType } from './my-dspace-configuration-value-type' ;
1620import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service' ;
1721import { PoolTaskSearchResult } from '../shared/object-collection/shared/pool-task-search-result.model' ;
@@ -75,6 +79,8 @@ export class MyDSpacePageComponent implements OnInit {
7579
7680 constructor (
7781 private service : SearchService ,
82+ private router : Router ,
83+ protected requestService : RequestService ,
7884 protected selectableListService : SelectableListService ,
7985 @Inject ( SEARCH_CONFIG_SERVICE ) public searchConfigService : MyDSpaceConfigurationService
8086 ) {
@@ -113,6 +119,25 @@ export class MyDSpacePageComponent implements OnInit {
113119
114120 }
115121
122+ /**
123+ * Refresh current page
124+ */
125+ refreshData ( searchResult : SearchResult < DSpaceObject > [ ] ) {
126+ if ( searchResult ?. length > 0 ) {
127+ // We use the same logic as the workspace action component as the search component need the cache to be emptied and the page to be reloaded
128+ this . router . navigated = false ;
129+ const url = decodeURIComponent ( this . router . url ) ;
130+ // override the route reuse strategy
131+ this . router . routeReuseStrategy . shouldReuseRoute = ( ) => {
132+ return false ;
133+ } ;
134+ // This assures that the search cache is empty before reloading mydspace.
135+ this . service . getEndpoint ( ) . pipe (
136+ take ( 1 ) ,
137+ tap ( ( cachedHref : string ) => this . requestService . removeByHrefSubstring ( cachedHref ) )
138+ ) . subscribe ( ( ) => this . router . navigateByUrl ( url ) ) ;
139+ }
140+ }
116141 /**
117142 * Deselect object from selection list
118143 * @param task
0 commit comments