Files
front/src/app/pages/cities-page/cities-page.ts
T
2026-10-07 18:25:55 +03:00

55 lines
1.5 KiB
TypeScript

import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { Store } from '@ngrx/store';
import {
areaOpenedCount,
areaProgress,
areaTotalCount,
type Area,
type Attraction,
} from '../../areas/area.models';
import {
GorodarActions,
selectAreas,
selectAreasError,
selectAreasStatus,
selectCollectedIdSet,
} from '../../state';
@Component({
selector: 'app-cities-page',
imports: [RouterLink],
templateUrl: './cities-page.html',
styleUrl: './cities-page.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CitiesPage {
private readonly store = inject(Store);
protected readonly areas = this.store.selectSignal(selectAreas);
protected readonly status = this.store.selectSignal(selectAreasStatus);
protected readonly error = this.store.selectSignal(selectAreasError);
protected readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
protected openedCount(area: Area): number {
return areaOpenedCount(area, this.collectedIds());
}
protected totalCount(area: Area): number {
return areaTotalCount(area);
}
protected progress(area: Area): number {
return areaProgress(area, this.collectedIds());
}
protected obtained(attraction: Attraction): boolean {
return attraction.visited || this.collectedIds().has(attraction.id);
}
protected reload(): void {
this.store.dispatch(GorodarActions.areasRequested());
}
}