11import { Component , OnInit , Input , OnDestroy , Output , EventEmitter } from '@angular/core' ;
22import { ImageSource , ImageListItemData } from '../image-source.model' ;
3- import { Subject } from 'rxjs' ;
4- import { takeUntil , startWith , switchMap , debounceTime } from 'rxjs/operators' ;
3+ import { Subject , throwError } from 'rxjs' ;
4+ import { takeUntil , startWith , switchMap , debounceTime , take , retryWhen , catchError } from 'rxjs/operators' ;
55import { TimoneerTabs } from '../../timoneer-tabs' ;
66import { ImagePreviewContainerComponentData } from '../image-preview-container/image-preview-container.component' ;
77import { TabService } from '../../tabs/tab.service' ;
@@ -31,6 +31,7 @@ export class ImageListComponent implements OnInit, OnDestroy {
3131 public error : string ;
3232
3333 protected readonly componetDestroyed = new Subject ( ) ;
34+ protected readonly retrySubject = new Subject ( ) ;
3435
3536 constructor (
3637 protected readonly tab : TabService ,
@@ -42,25 +43,34 @@ export class ImageListComponent implements OnInit, OnDestroy {
4243 . valueChanges
4344 . pipe (
4445 debounceTime ( 250 ) ,
45- takeUntil ( this . componetDestroyed ) ,
4646 startWith ( null ) ,
4747 switchMap ( ( v ) => {
4848 this . loading = true ;
4949 return this . source . loadList ( v ) ;
50- } )
50+ } ) ,
51+ catchError ( e => {
52+ this . loading = false ;
53+ this . error = e . message ;
54+ this . setTitle ( 'errored' ) ;
55+ console . error ( e ) ;
56+ return throwError ( e ) ;
57+ } ) ,
58+ retryWhen ( errors => errors . pipe ( switchMap ( ( ) => this . retrySubject . asObservable ( ) ) ) ) ,
59+ takeUntil ( this . componetDestroyed ) ,
5160 )
5261 . subscribe ( list => {
5362 this . loading = false ;
5463 this . images = list ;
5564 this . setTitle ( this . images . length . toString ( ) ) ;
56- } , e => {
57- this . loading = false ;
58- this . error = e . message ;
59- this . setTitle ( 'errored' ) ;
60- console . error ( e ) ;
6165 } ) ;
6266 }
6367
68+ public retry ( ) {
69+ this . loading = false ;
70+ this . error = null ;
71+ this . retrySubject . next ( ) ;
72+ }
73+
6474 public imageInfo ( image : ImageListItemData ) {
6575 this . tab . add ( TimoneerTabs . IMAGE_PREVIEW , {
6676 title : image . name ,
0 commit comments