-
Notifications
You must be signed in to change notification settings - Fork 27
/
coffee-list.view.ts
61 lines (52 loc) · 1.81 KB
/
coffee-list.view.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {
Component,
HostBinding,
OnInit,
OnDestroy,
ViewChild,
AfterViewInit,
} from '@angular/core';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {ActivatedRoute} from '@angular/router';
import {CoffeeListStore} from '../../services/coffee-list.store';
import {CoffeeListEndpoint} from '../../services/coffee-list.endpoint';
import {ModalComponent} from '../../../../shared/components/modal/modal.component';
import {COFFEE_LIST_CONFIG} from '../../coffee-list.config';
import * as sortHelpers from '../../../../shared/helpers/sort.helpers';
@Component({
templateUrl: './coffee-list.view.html',
styleUrls: ['./coffee-list.view.scss'],
providers: [CoffeeListStore, CoffeeListEndpoint],
})
export class CoffeeListView implements OnInit, AfterViewInit, OnDestroy {
@HostBinding('class')
cssClass = 'ce-view ce-coffee-list-view';
@ViewChild('detailsModal')
detailsModal: ModalComponent;
private ngUnsubscribe$: Subject<undefined> = new Subject();
constructor(public store: CoffeeListStore, private route: ActivatedRoute) {}
ngOnInit(): void {
this.store.init();
this.subscribeToQueryParamsUpdates();
}
ngAfterViewInit(): void {
this.store.setDetailsModal(this.detailsModal);
}
ngOnDestroy(): void {
this.ngUnsubscribe$.next();
this.ngUnsubscribe$.complete();
}
private subscribeToQueryParamsUpdates(): void {
this.route.queryParams
.pipe(takeUntil(this.ngUnsubscribe$))
.subscribe(params => {
this.store.sortCandidates(
sortHelpers.convertQueryParamsToSort(
params,
COFFEE_LIST_CONFIG.defaultSortField
)
);
});
}
}