1
1
import { Component , OnInit , Input , OnDestroy , Output , EventEmitter } from '@angular/core' ;
2
2
import { 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' ;
5
5
import { TimoneerTabs } from '../../timoneer-tabs' ;
6
6
import { ImagePreviewContainerComponentData } from '../image-preview-container/image-preview-container.component' ;
7
7
import { TabService } from '../../tabs/tab.service' ;
@@ -31,6 +31,7 @@ export class ImageListComponent implements OnInit, OnDestroy {
31
31
public error : string ;
32
32
33
33
protected readonly componetDestroyed = new Subject ( ) ;
34
+ protected readonly retrySubject = new Subject ( ) ;
34
35
35
36
constructor (
36
37
protected readonly tab : TabService ,
@@ -42,25 +43,34 @@ export class ImageListComponent implements OnInit, OnDestroy {
42
43
. valueChanges
43
44
. pipe (
44
45
debounceTime ( 250 ) ,
45
- takeUntil ( this . componetDestroyed ) ,
46
46
startWith ( null ) ,
47
47
switchMap ( ( v ) => {
48
48
this . loading = true ;
49
49
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 ) ,
51
60
)
52
61
. subscribe ( list => {
53
62
this . loading = false ;
54
63
this . images = list ;
55
64
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 ) ;
61
65
} ) ;
62
66
}
63
67
68
+ public retry ( ) {
69
+ this . loading = false ;
70
+ this . error = null ;
71
+ this . retrySubject . next ( ) ;
72
+ }
73
+
64
74
public imageInfo ( image : ImageListItemData ) {
65
75
this . tab . add ( TimoneerTabs . IMAGE_PREVIEW , {
66
76
title : image . name ,
0 commit comments