Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit f30183a

Browse files
author
Leonardo Chaia
committed
feat: adds Retry button when loading image list fails
1 parent 092b7c7 commit f30183a

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/app/docker-images/image-list/image-list.component.html

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<tim-loading *ngIf="loading"></tim-loading>
2-
<mat-card *ngIf="error"
3-
class="tim-bg-warn">
4-
{{error}}
5-
</mat-card>
2+
<ng-container *ngIf="error">
3+
<mat-card class="tim-bg-warn">
4+
{{error}}
5+
</mat-card>
6+
<div style="text-align: right">
7+
<button type="button"
8+
mat-raised-button
9+
(click)="retry()"
10+
color="primary">
11+
<mat-icon>refresh</mat-icon>
12+
Retry
13+
</button>
14+
</div>
15+
</ng-container>
616
<mat-card *ngFor="let image of images">
717
<div fxLayout="row"
818
fxLayoutAlign="start center"

src/app/docker-images/image-list/image-list.component.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit, Input, OnDestroy, Output, EventEmitter } from '@angular/core';
22
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';
55
import { TimoneerTabs } from '../../timoneer-tabs';
66
import { ImagePreviewContainerComponentData } from '../image-preview-container/image-preview-container.component';
77
import { 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

Comments
 (0)