Skip to content

Commit

Permalink
Step 13.20: Add reactive search by location
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Dec 14, 2016
1 parent a90b23b commit 213ca94
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/imports/app/parties/parties-list.component.ts
Expand Up @@ -35,6 +35,7 @@ export class PartiesListComponent implements OnInit, OnDestroy {
optionsSub: Subscription;
partiesSize: number = 0;
autorunSub: Subscription;
location: Subject<string> = new Subject<string>();

constructor(
private paginationService: PaginationService
Expand All @@ -44,8 +45,9 @@ export class PartiesListComponent implements OnInit, OnDestroy {
this.optionsSub = Observable.combineLatest(
this.pageSize,
this.curPage,
this.nameOrder
).subscribe(([pageSize, curPage, nameOrder]) => {
this.nameOrder,
this.location
).subscribe(([pageSize, curPage, nameOrder, location]) => {
const options: Options = {
limit: pageSize as number,
skip: ((curPage as number) - 1) * (pageSize as number),
Expand All @@ -58,7 +60,7 @@ export class PartiesListComponent implements OnInit, OnDestroy {
this.partiesSub.unsubscribe();
}

this.partiesSub = MeteorObservable.subscribe('parties', options).subscribe(() => {
this.partiesSub = MeteorObservable.subscribe('parties', options, location).subscribe(() => {
this.parties = Parties.find({}, {
sort: {
name: nameOrder
Expand All @@ -77,6 +79,7 @@ export class PartiesListComponent implements OnInit, OnDestroy {
this.pageSize.next(10);
this.curPage.next(1);
this.nameOrder.next(1);
this.location.next('');

this.autorunSub = MeteorObservable.autorun().subscribe(() => {
this.partiesSize = Counts.get('numberOfParties');
Expand All @@ -89,7 +92,8 @@ export class PartiesListComponent implements OnInit, OnDestroy {
}

search(value: string): void {
this.parties = Parties.find(value ? { location: value } : {}).zone();
this.curPage.next(1);
this.location.next(value);
}

onPageChanged(page: number): void {
Expand Down

0 comments on commit 213ca94

Please sign in to comment.