-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbatch-card.component.ts
39 lines (32 loc) · 1.13 KB
/
batch-card.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Store } from "@ngrx/store";
import { map } from "rxjs/operators";
import { selectDatasetsInBatch } from "state-management/selectors/datasets.selectors";
import { clearBatchAction } from "state-management/actions/datasets.actions";
import { Subscription } from "rxjs";
@Component({
selector: "batch-card",
templateUrl: "./batch-card.component.html",
styleUrls: ["./batch-card.component.scss"],
})
export class BatchCardComponent implements OnInit, OnDestroy {
private batch$ = this.store.select(selectDatasetsInBatch);
public batchSize$ = this.batch$.pipe(map((batch) => batch.length));
public nonEmpty$ = this.batchSize$.pipe(map((size) => size > 0));
batchSizeSubscription: Subscription = new Subscription();
batchSize = 0;
constructor(private store: Store) {}
ngOnInit() {
this.batchSizeSubscription = this.batchSize$.subscribe((size) => {
if (size) {
this.batchSize = size;
}
});
}
ngOnDestroy() {
this.batchSizeSubscription.unsubscribe();
}
public clear(): void {
this.store.dispatch(clearBatchAction());
}
}