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
+49 -32
View File
@@ -1,18 +1,26 @@
@if (landmark(); as item) {
@if (claiming()) {
<app-claim-flow [landmark]="item" />
<app-claim-flow
[landmark]="item"
[cityName]="area()?.name ?? ''"
[opened]="openedCount()"
[total]="totalCount()"
[areaId]="areaId()"
/>
} @else {
<article class="object" [class.object--owned]="collected()">
<header class="object__hero">
<img class="object__hero-img" [src]="item.background" alt="" />
@if (item.backgroundUrl || item.photoUrl) {
<img class="object__hero-img" [src]="item.backgroundUrl || item.photoUrl" alt="" />
}
<button class="object__back" type="button" aria-label="Назад" (click)="goBack()">
<app-icon name="chevron-left" [size]="22" />
</button>
<span class="object__city">{{ city.name }}</span>
<span class="object__city">{{ area()?.name }}</span>
</header>
<div class="object__intro">
<h1>{{ item.title }}</h1>
<h1>{{ item.name }}</h1>
<div class="object__chips">
<span class="chip" [class.chip--open]="collected()">
@@ -21,39 +29,44 @@
</span>
</div>
<div class="object__address">
<app-icon name="pin" [size]="18" />
<div>
<p>{{ item.address }}</p>
<span>{{ item.addressHint }}</span>
@if (item.address) {
<div class="object__address">
<app-icon name="pin" [size]="18" />
<div>
<p>{{ item.address }}</p>
</div>
</div>
</div>
}
</div>
<div class="object__body">
<section>
<h2>О месте</h2>
<p>{{ item.description }}</p>
</section>
@if (item.about) {
<section>
<h2>О месте</h2>
<p>{{ item.about }}</p>
</section>
}
<section>
<h2>Аудиогид</h2>
<app-audio-guide [src]="item.audio" />
</section>
@if (item.facts.length > 0) {
<section>
<h2>Интересные факты</h2>
<ol class="facts">
@for (fact of item.facts; track fact; let index = $index) {
<li>
<span class="facts__number">{{ index + 1 }}</span>
<span class="facts__value">{{ fact }}</span>
</li>
}
</ol>
</section>
}
<section>
<h2>Интересные факты</h2>
<ol class="facts">
@for (fact of item.facts; track fact; let index = $index) {
<li>
<span class="facts__number">{{ index + 1 }}</span>
<span class="facts__value">
{{ fact }}
</span>
</li>
}
</ol>
</section>
@if (item.audioUrl) {
<section>
<h2>Аудиогид</h2>
<app-audio-guide [src]="item.audioUrl" />
</section>
}
@if (collected()) {
<section>
@@ -111,9 +124,13 @@
</div>
}
}
} @else if (status() === 'loading') {
<section class="object object--empty">
<p>Загружаем…</p>
</section>
} @else {
<section class="object object--empty">
<p>Объект не найден.</p>
<p>{{ error() || 'Объект не найден.' }}</p>
<button matButton="outlined" type="button" (click)="goBack()">Назад</button>
</section>
}
+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 {