Skip to content

Commit

Permalink
fix(gathering): gathering pages should perform better
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Mar 8, 2023
1 parent 88ccef5 commit d977d18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ion-row>

<ion-row>
<ion-col [sizeMd]="4" *ngFor="let location of visibleLocations(locationData.locations, skillLevel.level || 0)">
<ion-col [sizeMd]="4" *ngFor="let location of locations">
<ion-card class="location-card">
<ion-card-header>
<ion-card-title>{{ location.name }}</ion-card-title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { IGameGatherLocation, IGameWorkersGathering } from '../../../interfaces';
import { AssignGatheringWorker, UnassignGatheringWorker } from '../../../stores/workers/workers.actions';

Expand All @@ -9,7 +9,7 @@ import { AssignGatheringWorker, UnassignGatheringWorker } from '../../../stores/
templateUrl: './gathering-page-display.component.html',
styleUrls: ['./gathering-page-display.component.scss'],
})
export class GatheringPageDisplayComponent implements OnInit {
export class GatheringPageDisplayComponent implements OnInit, OnDestroy {

@Input() tradeskill = '';
@Input() level$!: Observable<number>;
Expand All @@ -25,9 +25,20 @@ export class GatheringPageDisplayComponent implements OnInit {
@Input() setAction: any;
@Input() cancelAction: any;

public locations: IGameGatherLocation[] = [];
private locSub!: Subscription;

constructor(private store: Store) { }

ngOnInit() {}
ngOnInit() {
this.locSub = this.level$.subscribe(level => {
this.locations = this.visibleLocations(this.locationData.locations, level);
});
}

ngOnDestroy() {
this.locSub?.unsubscribe();
}

visibleLocations(locations: IGameGatherLocation[], currentLevel = 0) {
return locations.filter(location => currentLevel >= location.level.min);
Expand Down

0 comments on commit d977d18

Please sign in to comment.