add logic

This commit is contained in:
2026-10-07 17:32:25 +03:00
parent cdcdd22526
commit f86777e2cd
69 changed files with 1519 additions and 637 deletions
+44 -6
View File
@@ -3,6 +3,7 @@ import {
ChangeDetectionStrategy,
Component,
computed,
effect,
HostListener,
inject,
input,
@@ -12,12 +13,17 @@ import { MatButton } from '@angular/material/button';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { areaOpenedCount, areaTotalCount, isObtained, type AreaDetails } from '../../areas/area.models';
import { ClaimFlow } from '../../claim/claim-flow/claim-flow';
import { CityCatalogService } from '../../root/services/city-catalog.service';
import { AudioGuide } from '../../shared/audio-guide/audio-guide';
import { Icon } from '../../shared/icon/icon';
import {
GorodarActions,
selectAreaDetails,
selectAreaDetailStatus,
selectAttractionError,
selectAttractions,
selectAttractionStatus,
selectAuthenticated,
selectClaim,
selectCollectedAt,
@@ -33,24 +39,39 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MapItemPage {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
private readonly location = inject(Location);
private readonly router = inject(Router);
private readonly authenticated = this.store.selectSignal(selectAuthenticated);
private readonly details = this.store.selectSignal(selectAreaDetails);
private readonly detailStatus = this.store.selectSignal(selectAreaDetailStatus);
private readonly attractions = this.store.selectSignal(selectAttractions);
private readonly attractionStatuses = this.store.selectSignal(selectAttractionStatus);
private readonly attractionErrors = this.store.selectSignal(selectAttractionError);
readonly areaId = input.required<string>();
readonly id = input.required<string>();
protected readonly city = this.catalog.city;
protected readonly landmark = computed(() => this.catalog.landmarkById(this.id()));
protected readonly status = computed(() => this.attractionStatuses()[this.id()] ?? 'loading');
protected readonly error = computed(() => this.attractionErrors()[this.id()] ?? '');
protected readonly area = computed((): AreaDetails | null => this.details()[this.areaId()] ?? null);
protected readonly landmark = computed(() => this.attractions()[this.id()] ?? null);
protected readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
protected readonly photos = this.store.selectSignal(selectPhotos);
protected readonly collectedAtMap = this.store.selectSignal(selectCollectedAt);
protected readonly claim = this.store.selectSignal(selectClaim);
protected readonly openedCount = computed(() => {
const area = this.area();
return area ? areaOpenedCount(area, this.collectedIds()) : 0;
});
protected readonly totalCount = computed(() => {
const area = this.area();
return area ? areaTotalCount(area) : 0;
});
protected readonly collected = computed(() => {
const item = this.landmark();
return item ? this.collectedIds().has(item.id) || item.collected : false;
return item ? isObtained(item, this.collectedIds()) : false;
});
protected readonly userPhoto = computed(() => {
@@ -85,13 +106,30 @@ export class MapItemPage {
protected readonly photoOpen = signal(false);
constructor() {
effect(() => {
const areaId = this.areaId();
const status = this.detailStatus()[areaId];
if (this.details()[areaId] || status === 'loading' || status === 'ready') {
return;
}
this.store.dispatch(GorodarActions.areaRequested({ id: areaId }));
});
effect(() => {
this.store.dispatch(GorodarActions.attractionRequested({ id: this.id() }));
});
}
protected goBack(): void {
if (window.history.length > 1) {
this.location.back();
return;
}
void this.router.navigateByUrl('/city');
void this.router.navigate(['/city', this.areaId()]);
}
protected claimItem(): void {