cancel subscriptions
parent
819cdbfe60
commit
0c1265ad09
|
@ -30,8 +30,7 @@
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<mat-progress-bar *ngIf="(ipfs || ipns) && dataSource && gateways" mode="determinate"
|
<mat-progress-bar *ngIf="subscriptions.length" mode="determinate" [value]="dataSource.data.length / gateways.length * 100">
|
||||||
[value]="dataSource.data.length / gateways.length * 100">
|
|
||||||
</mat-progress-bar>
|
</mat-progress-bar>
|
||||||
|
|
||||||
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
|
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
|
||||||
|
@ -53,10 +52,10 @@
|
||||||
<td mat-cell *matCellDef="let element">
|
<td mat-cell *matCellDef="let element">
|
||||||
<div [ngSwitch]="element.error">
|
<div [ngSwitch]="element.error">
|
||||||
<div *ngSwitchCase="null">
|
<div *ngSwitchCase="null">
|
||||||
<strong><a [href]="element.gateway" class="aqua"> {{ element.gateway }} </a></strong>
|
<strong><a href="{{ element.gateway }}#x-ipfs-companion-no-redirect" class="aqua"> {{ element.gateway }} </a></strong>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchDefault>
|
<div *ngSwitchDefault>
|
||||||
<a [href]="element.gateway" class="aqua-muted"> {{ element.gateway }} </a>
|
<a href="{{ element.gateway }}#x-ipfs-companion-no-redirect" class="aqua-muted"> {{ element.gateway }} </a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { MatTable, MatTableDataSource } from '@angular/material/table';
|
import { MatTable, MatTableDataSource } from '@angular/material/table';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
import { GatewayService } from '../services/gateway.service';
|
import { GatewayService } from '../services/gateway.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -18,6 +19,7 @@ export class PagesComponent implements OnInit {
|
||||||
'error',
|
'error',
|
||||||
'gateway',
|
'gateway',
|
||||||
];
|
];
|
||||||
|
subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
@ViewChild(MatTable, { static: false }) matTable: MatTable<Result>;
|
@ViewChild(MatTable, { static: false }) matTable: MatTable<Result>;
|
||||||
|
|
||||||
|
@ -39,17 +41,27 @@ export class PagesComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
cache(type: string, hash: string): void {
|
cache(type: string, hash: string): void {
|
||||||
|
|
||||||
|
while (this.subscriptions.length) {
|
||||||
|
const sub = this.subscriptions.pop();
|
||||||
|
if (!sub.closed) {
|
||||||
|
sub.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.dataSource.data = [];
|
this.dataSource.data = [];
|
||||||
this.matTable.renderRows();
|
this.matTable.renderRows();
|
||||||
|
|
||||||
this.gateways.forEach(gateway => {
|
this.gateways.forEach(gateway => {
|
||||||
this.gatewayService.get(gateway, type, hash).subscribe(_ => {
|
this.subscriptions.push(
|
||||||
this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error: null });
|
this.gatewayService.get(gateway, type, hash).subscribe(_ => {
|
||||||
this.matTable.renderRows();
|
this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error: null });
|
||||||
}, (error: HttpErrorResponse) => {
|
this.matTable.renderRows();
|
||||||
this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error });
|
}, (error: HttpErrorResponse) => {
|
||||||
this.matTable.renderRows();
|
this.dataSource.data.push({ gateway: `${gateway.replace(':type', type).replace(':hash', hash)}`, error });
|
||||||
});
|
this.matTable.renderRows();
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue