@@ -186,21 +186,25 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
186186 ) ;
187187 } )
188188 ) . subscribe ( ( rd : RemoteData < PaginatedList < SearchResult < DSpaceObject > > > ) => {
189- this . loading = false ;
190- const currentEntries = this . listEntries$ . getValue ( ) ;
191- if ( rd . hasSucceeded ) {
192- if ( hasNoValue ( currentEntries ) ) {
193- this . listEntries$ . next ( rd . payload . page ) ;
194- } else {
195- this . listEntries$ . next ( [ ... currentEntries , ... rd . payload . page ] ) ;
196- }
197- // Check if there are more pages available after the current one
198- this . hasNextPage = rd . payload . totalElements > this . listEntries$ . getValue ( ) . length ;
189+ this . updateList ( rd ) ;
190+ } ) ) ;
191+ }
192+
193+ updateList ( rd : RemoteData < PaginatedList < SearchResult < DSpaceObject > > > ) {
194+ this . loading = false ;
195+ const currentEntries = this . listEntries$ . getValue ( ) ;
196+ if ( rd . hasSucceeded ) {
197+ if ( hasNoValue ( currentEntries ) ) {
198+ this . listEntries$ . next ( rd . payload . page ) ;
199199 } else {
200- this . listEntries$ . next ( [ ...( hasNoValue ( currentEntries ) ? [ ] : this . listEntries$ . getValue ( ) ) , new ListableNotificationObject ( NotificationType . Error , 'dso-selector.results-could-not-be-retrieved' , LISTABLE_NOTIFICATION_OBJECT . value ) ] ) ;
201- this . hasNextPage = false ;
200+ this . listEntries$ . next ( [ ...currentEntries , ...rd . payload . page ] ) ;
202201 }
203- } ) ) ;
202+ // Check if there are more pages available after the current one
203+ this . hasNextPage = rd . payload . totalElements > this . listEntries$ . getValue ( ) . length ;
204+ } else {
205+ this . listEntries$ . next ( [ ...( hasNoValue ( currentEntries ) ? [ ] : this . listEntries$ . getValue ( ) ) , new ListableNotificationObject ( NotificationType . Error , 'dso-selector.results-could-not-be-retrieved' , LISTABLE_NOTIFICATION_OBJECT . value ) ] ) ;
206+ this . hasNextPage = false ;
207+ }
204208 }
205209
206210 /**
@@ -214,16 +218,19 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
214218 * Perform a search for the current query and page
215219 * @param query Query to search objects for
216220 * @param page Page to retrieve
221+ * @param useCache Whether or not to use the cache
217222 */
218- search ( query : string , page : number ) : Observable < RemoteData < PaginatedList < SearchResult < DSpaceObject > > > > {
223+ search ( query : string , page : number , useCache : boolean = true ) : Observable < RemoteData < PaginatedList < SearchResult < DSpaceObject > > > > {
219224 return this . searchService . search (
220225 new PaginatedSearchOptions ( {
221226 query : query ,
222227 dsoTypes : this . types ,
223228 pagination : Object . assign ( { } , this . defaultPagination , {
224229 currentPage : page
225230 } )
226- } )
231+ } ) ,
232+ null ,
233+ useCache ,
227234 ) . pipe (
228235 getFirstCompletedRemoteData ( )
229236 ) ;
@@ -266,12 +273,21 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
266273 }
267274
268275 /**
269- * Emits only when the {@link listableObject} is a {@link DSpaceObject}.
276+ * Handles the user clicks on the {@link ListableObject}s. When the {@link listableObject} is a
277+ * {@link ListableObject} it will retry the error when the user clicks it. Otherwise it will emit the {@link onSelect}.
270278 *
271279 * @param listableObject The {@link ListableObject} to evaluate
272280 */
273281 onClick ( listableObject : ListableObject ) : void {
274282 if ( listableObject . getRenderTypes ( ) . includes ( LISTABLE_NOTIFICATION_OBJECT . value ) ) {
283+ this . listEntries$ . value . pop ( ) ;
284+ this . hasNextPage = true ;
285+ this . search ( this . input . value ? this . input . value : '' , this . currentPage$ . value , false ) . pipe (
286+ getFirstCompletedRemoteData ( ) ,
287+ ) . subscribe ( ( rd : RemoteData < PaginatedList < SearchResult < DSpaceObject > > > ) => {
288+ this . updateList ( rd ) ;
289+ } ) ;
290+ } else {
275291 this . onSelect . emit ( ( listableObject as SearchResult < DSpaceObject > ) . indexableObject ) ;
276292 }
277293 }
0 commit comments