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
+43 -40
View File
@@ -4,50 +4,53 @@
<p>Приезжайте на место, снимайте — объект попадёт в вашу коллекцию.</p>
</div>
@if (status() === 'loading' && areas().length === 0) {
<p class="cities__status">Загружаем города…</p>
} @else if (status() === 'error' && areas().length === 0) {
<p class="cities__status">{{ error() }}</p>
<button type="button" (click)="reload()">Повторить</button>
}
<div class="cities">
<a class="city-card" routerLink="/city" [attr.aria-label]="city.name">
<div class="city-card__top">
<div>
<h2>{{ city.name }}</h2>
<p>
Открыто
<strong>{{ openedCount() }} из {{ totalCount }}</strong>
объектов
</p>
</div>
@for (area of areas(); track area.id) {
@if (area.attractions.length === 0) {
<article class="city-card city-card--soon">
<h2>{{ area.name }}</h2>
<p>Скоро появится</p>
</article>
} @else {
<a class="city-card" [routerLink]="['/city', area.id]" [attr.aria-label]="area.name">
<div class="city-card__top">
<div>
<h2>{{ area.name }}</h2>
<p>
Открыто
<strong>{{ openedCount(area) }} из {{ totalCount(area) }}</strong>
объектов
</p>
</div>
<div class="city-card__percent" aria-hidden="true">{{ progress() }}%</div>
</div>
<div class="city-card__percent" aria-hidden="true">{{ progress(area) }}%</div>
</div>
<mat-progress-bar mode="determinate" [value]="progress()" />
<mat-progress-bar mode="determinate" [value]="progress(area)" />
<div class="city-card__cells">
@for (landmark of city.objects; track landmark.id) {
<span
class="cell"
[class.cell--open]="collectedIds().has(landmark.id)"
[attr.aria-label]="
landmark.title + (collectedIds().has(landmark.id) ? ', получено' : ', не получен')
"
>
<img
[src]="
collectedIds().has(landmark.id)
? landmark.achievement
: '/assets/icons/cell-lock.svg'
"
[alt]=""
/>
</span>
}
</div>
</a>
@for (name of upcomingCities; track name) {
<article class="city-card city-card--soon">
<h2>{{ name }}</h2>
<p>Скоро появится</p>
</article>
<div class="city-card__cells">
@for (attraction of area.attractions; track attraction.id) {
<span
class="cell"
[class.cell--open]="obtained(attraction)"
[attr.aria-label]="attraction.name + (obtained(attraction) ? ', получено' : ', не получен')"
>
<img
[src]="obtained(attraction) && attraction.iconUrl ? attraction.iconUrl : '/assets/icons/cell-lock.svg'"
[alt]=""
/>
</span>
}
</div>
</a>
}
}
</div>
</section>
+25 -8
View File
@@ -3,8 +3,8 @@ import { MatProgressBar } from '@angular/material/progress-bar';
import { RouterLink } from '@angular/router';
import { Store } from '@ngrx/store';
import { CityCatalogService } from '../../root/services/city-catalog.service';
import { selectCollectedIdSet, selectOpenedCount, selectProgress } from '../../state';
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',
@@ -14,13 +14,30 @@ import { selectCollectedIdSet, selectOpenedCount, selectProgress } from '../../s
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CitiesPage {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
protected readonly city = this.catalog.city;
protected readonly upcomingCities = ['Москва', 'Санкт-Петербург'];
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 readonly openedCount = this.store.selectSignal(selectOpenedCount);
protected readonly totalCount = this.city.objects.length;
protected readonly progress = this.store.selectSignal(selectProgress);
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());
}
}
+27 -16
View File
@@ -5,6 +5,7 @@
</a>
</header>
@if (area(); as city) {
<div class="page__city">
<img src="/assets/icons/gorodar-mark.svg" alt="" width="96" height="96" />
<div>
@@ -12,7 +13,7 @@
<p>
<app-icon name="pin" [size]="18" />
<span>
<b>{{ openedCount() }}/{{ city.objects.length }}</b>
<b>{{ openedCount() }}/{{ totalCount() }}</b>
объектов
</span>
<span>·</span>
@@ -43,14 +44,18 @@
</button>
</nav>
@if (tab() === 'objects') {
@if (tab() === 'objects' && totalCount() === 0) {
<p class="page__status">В этом городе пока нет объектов.</p>
}
@if (tab() === 'objects' && totalCount() > 0) {
<div class="filters">
<button
type="button"
[class.filters__item--active]="filter() === 'all'"
(click)="filter.set('all')"
>
Все · {{ city.objects.length }}
Все · {{ totalCount() }}
</button>
<button
type="button"
@@ -71,8 +76,8 @@
<div class="grid">
@for (landmark of landmarks(); track landmark.id) {
<a class="card" [routerLink]="objectRoute(landmark.id)">
<div class="card__preview" [class.card__preview--open]="collectedIds().has(landmark.id)">
@if (collectedIds().has(landmark.id)) {
<div class="card__preview" [class.card__preview--open]="isOpen(landmark)">
@if (isOpen(landmark)) {
<svg class="card__rays" viewBox="0 0 112 112" aria-hidden="true">
@for (ray of rays; track $index) {
<line
@@ -93,22 +98,18 @@
<span class="card__spark card__spark--d"></span>
}
<img
[src]="
collectedIds().has(landmark.id)
? landmark.achievement
: '/assets/icons/cell-lock.svg'
"
[src]="isOpen(landmark) && landmark.iconUrl ? landmark.iconUrl : '/assets/icons/cell-lock.svg'"
alt=""
/>
</div>
<div class="card__body">
<h2>{{ landmark.title }}</h2>
<span class="card__status" [class.card__status--open]="collectedIds().has(landmark.id)">
<app-icon [name]="collectedIds().has(landmark.id) ? 'check' : 'lock'" [size]="15" />
{{ collectedIds().has(landmark.id) ? 'Получен' : 'Не получен' }}
<h2>{{ landmark.name }}</h2>
<span class="card__status" [class.card__status--open]="isOpen(landmark)">
<app-icon [name]="isOpen(landmark) ? 'check' : 'lock'" [size]="15" />
{{ isOpen(landmark) ? 'Получен' : 'Не получен' }}
</span>
</div>
<span class="card__bar" [class.card__bar--open]="collectedIds().has(landmark.id)"></span>
<span class="card__bar" [class.card__bar--open]="isOpen(landmark)"></span>
</a>
}
</div>
@@ -116,7 +117,17 @@
@if (mapReady()) {
<div class="page__map" [class.page__map--off]="tab() !== 'map'">
<app-city-map [embedded]="true" />
<app-city-map
[embedded]="true"
[cityName]="city.name"
[areaId]="areaId()"
[attractions]="mapAttractions()"
/>
</div>
}
} @else if (status() === 'loading') {
<p class="page__status">Загружаем город…</p>
} @else {
<p class="page__status">{{ error() || 'Город не найден.' }}</p>
}
</section>
+62 -12
View File
@@ -1,11 +1,25 @@
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, effect, inject, input, signal } from '@angular/core';
import { RouterLink } from '@angular/router';
import { Store } from '@ngrx/store';
import {
areaAttractions,
areaOpenedCount,
areaProgress,
areaTotalCount,
findAttraction,
isObtained,
type Attraction,
} from '../../areas/area.models';
import { CityMap } from '../../map/city-map/city-map';
import { CityCatalogService } from '../../root/services/city-catalog.service';
import { Icon } from '../../shared/icon/icon';
import { selectCollectedIdSet, selectOpenedCount, selectProgress } from '../../state';
import {
GorodarActions,
selectAreaDetailError,
selectAreaDetails,
selectAreaDetailStatus,
selectCollectedIdSet,
} from '../../state';
type CollectionFilter = 'all' | 'open' | 'closed';
type CityTab = 'objects' | 'map';
@@ -18,26 +32,47 @@ type CityTab = 'objects' | 'map';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CityPage {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
protected readonly city = this.catalog.city;
readonly areaId = input.required<string>();
private readonly details = this.store.selectSignal(selectAreaDetails);
private readonly detailStatus = this.store.selectSignal(selectAreaDetailStatus);
private readonly detailError = this.store.selectSignal(selectAreaDetailError);
protected readonly status = computed(() => this.detailStatus()[this.areaId()] ?? 'loading');
protected readonly error = computed(() => this.detailError()[this.areaId()] ?? '');
protected readonly area = computed(() => this.details()[this.areaId()] ?? null);
protected readonly tab = signal<CityTab>('objects');
protected readonly mapReady = signal(false);
protected readonly filter = signal<CollectionFilter>('all');
protected readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
protected readonly openedCount = this.store.selectSignal(selectOpenedCount);
protected readonly progress = this.store.selectSignal(selectProgress);
protected readonly closedCount = computed(() => this.city.objects.length - this.openedCount());
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 progress = computed(() => {
const area = this.area();
return area ? areaProgress(area, this.collectedIds()) : 0;
});
protected readonly closedCount = computed(() => this.totalCount() - this.openedCount());
protected readonly mapAttractions = computed(() => {
const area = this.area();
return area ? areaAttractions(area) : [];
});
protected readonly landmarks = computed(() => {
const items = this.city.objects;
const current = this.area();
const items = current ? areaAttractions(current) : [];
const ids = this.collectedIds();
switch (this.filter()) {
case 'open':
return items.filter((item) => ids.has(item.id));
return items.filter((item) => isObtained(item, ids));
case 'closed':
return items.filter((item) => !ids.has(item.id));
return items.filter((item) => !isObtained(item, ids));
default:
return items;
}
@@ -58,6 +93,12 @@ export class CityPage {
};
});
constructor() {
effect(() => {
this.store.dispatch(GorodarActions.areaRequested({ id: this.areaId() }));
});
}
protected openObjects(): void {
this.tab.set('objects');
}
@@ -67,7 +108,16 @@ export class CityPage {
this.tab.set('map');
}
protected isOpen(attraction: Attraction): boolean {
return isObtained(attraction, this.collectedIds());
}
protected objectRoute(id: string): string[] {
return this.collectedIds().has(id) ? ['/city', id, 'icon'] : ['/city', id];
const current = this.area();
const attraction = current ? findAttraction(current, id) : null;
const open = attraction ? isObtained(attraction, this.collectedIds()) : false;
return open
? ['/city', this.areaId(), id, 'icon']
: ['/city', this.areaId(), id];
}
}
@@ -1,10 +1,12 @@
<section class="page">
<header class="account">
<p class="account__email">{{ accountEmail() }}</p>
<button class="account__logout" type="button" aria-label="Выйти" (click)="logout()">
<app-icon name="logout" [size]="22" />
</button>
</header>
@if (authenticated()) {
<header class="account">
<p class="account__email">{{ accountEmail() }}</p>
<button class="account__logout" type="button" aria-label="Выйти" (click)="logout()">
<app-icon name="logout" [size]="22" />
</button>
</header>
}
<div class="page__intro">
<h1>Вся коллекция</h1>
@@ -17,46 +19,48 @@
<span>{{ objectsLabel() }}</span>
</div>
<div>
<b>1</b>
<span>город</span>
<b>{{ packs().length }}</b>
<span>{{ citiesLabel() }}</span>
</div>
</section>
<p class="section-label">Мои города</p>
@if (collectedLandmarks().length > 0) {
<article class="pack">
<a class="pack__head" routerLink="/city" [attr.aria-label]="'Объекты: ' + city.name">
<div>
<h2>{{ city.name }}</h2>
<p>Собрано {{ openedCount() }} из {{ totalCount }}</p>
</div>
<div class="pack__percent anim-percent" [style.--to-p]="progress()" aria-hidden="true">
<span>{{ progress() }}%</span>
</div>
<span class="pack__go" aria-hidden="true">
<app-icon name="chevron-right" [size]="20" />
</span>
</a>
@if (packs().length > 0) {
@for (pack of packs(); track pack.area.id) {
<article class="pack">
<a class="pack__head" [routerLink]="['/city', pack.area.id]" [attr.aria-label]="'Объекты: ' + pack.area.name">
<div>
<h2>{{ pack.area.name }}</h2>
<p>Собрано {{ pack.opened }} из {{ pack.total }}</p>
</div>
<div class="pack__percent anim-percent" [style.--to-p]="pack.progress" aria-hidden="true">
<span>{{ pack.progress }}%</span>
</div>
<span class="pack__go" aria-hidden="true">
<app-icon name="chevron-right" [size]="20" />
</span>
</a>
<div class="pack__bar" aria-hidden="true">
<span class="anim-grow" [style.--from]="'0%'" [style.--to]="progress() + '%'"></span>
</div>
<div class="pack__bar" aria-hidden="true">
<span class="anim-grow" [style.--from]="'0%'" [style.--to]="pack.progress + '%'"></span>
</div>
<div class="picked">
@for (landmark of collectedLandmarks(); track landmark.id) {
<a class="picked__card" [routerLink]="objectRoute(landmark.id)">
<div class="picked__preview">
<img [src]="landmark.achievement" alt="" />
</div>
<div class="picked__body">
<h3>{{ landmark.title }}</h3>
</div>
<span class="picked__bar" aria-hidden="true"></span>
</a>
}
</div>
</article>
<div class="picked">
@for (landmark of pack.items; track landmark.id) {
<a class="picked__card" [routerLink]="objectRoute(pack.area.id, landmark)">
<div class="picked__preview">
<img [src]="landmark.iconUrl" alt="" />
</div>
<div class="picked__body">
<h3>{{ landmark.name }}</h3>
</div>
<span class="picked__bar" aria-hidden="true"></span>
</a>
}
</div>
</article>
}
} @else {
<p class="empty">Пока нет полученных объектов.</p>
}
@@ -2,16 +2,23 @@ import { afterNextRender, ChangeDetectionStrategy, Component, computed, inject }
import { RouterLink } from '@angular/router';
import { Store } from '@ngrx/store';
import { CityCatalogService } from '../../root/services/city-catalog.service';
import {
areaAttractions,
areaOpenedCount,
areaProgress,
areaTotalCount,
isObtained,
type Attraction,
} from '../../areas/area.models';
import { Icon } from '../../shared/icon/icon';
import {
GorodarActions,
selectAreas,
selectAuthEmail,
selectAuthenticated,
selectCollectedIdSet,
selectOpenedCount,
selectProfile,
selectProgress,
} from '../../state';
@Component({
@@ -22,23 +29,30 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CollectionsPage {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
protected readonly city = this.catalog.city;
private readonly areas = this.store.selectSignal(selectAreas);
protected readonly profile = this.store.selectSignal(selectProfile);
protected readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
protected readonly openedCount = this.store.selectSignal(selectOpenedCount);
protected readonly totalCount = this.city.objects.length;
protected readonly progress = this.store.selectSignal(selectProgress);
private readonly authenticated = this.store.selectSignal(selectAuthenticated);
protected readonly authenticated = this.store.selectSignal(selectAuthenticated);
private readonly authEmail = this.store.selectSignal(selectAuthEmail);
protected readonly accountEmail = computed(() =>
this.authenticated() ? this.authEmail() : this.profile().email,
);
protected readonly collectedLandmarks = computed(() =>
this.city.objects.filter((item) => this.collectedIds().has(item.id)),
);
protected readonly packs = computed(() => {
const ids = this.collectedIds();
return this.areas()
.map((area) => ({
area,
items: areaAttractions(area).filter((item) => isObtained(item, ids)),
opened: areaOpenedCount(area, ids),
total: areaTotalCount(area),
progress: areaProgress(area, ids),
}))
.filter((pack) => pack.items.length > 0);
});
constructor() {
afterNextRender(() => {
@@ -50,8 +64,14 @@ export class CollectionsPage {
this.plural(this.openedCount(), ['объект', 'объекта', 'объектов']),
);
protected objectRoute(id: string): string[] {
return this.collectedIds().has(id) ? ['/city', id, 'icon'] : ['/city', id];
protected readonly citiesLabel = computed(() =>
this.plural(this.packs().length, ['город', 'города', 'городов']),
);
protected objectRoute(areaId: string, attraction: Attraction): string[] {
return isObtained(attraction, this.collectedIds())
? ['/city', areaId, attraction.id, 'icon']
: ['/city', areaId, attraction.id];
}
protected logout(): void {
@@ -2,14 +2,19 @@
@if (collected()) {
<app-collect-success
mode="preview"
[title]="item.title"
[image]="item.achievement"
[model]="item.model"
[title]="item.name"
[image]="item.iconUrl"
[model]="item.modelUrl || undefined"
[areaId]="areaId()"
/>
}
} @else if (status() === 'loading') {
<section class="missing">
<p>Загружаем…</p>
</section>
} @else {
<section class="missing">
<p>Объект не найден.</p>
<a routerLink="/city">К списку объектов</a>
<a [routerLink]="['/city', areaId()]">К списку объектов</a>
</section>
}
@@ -2,9 +2,9 @@ import { ChangeDetectionStrategy, Component, computed, effect, inject, input } f
import { Router, RouterLink } from '@angular/router';
import { Store } from '@ngrx/store';
import { findAttraction, isObtained } from '../../areas/area.models';
import { CollectSuccess } from '../../claim/collect-success/collect-success';
import { CityCatalogService } from '../../root/services/city-catalog.service';
import { selectCollectedIdSet } from '../../state';
import { GorodarActions, selectAreaDetails, selectAreaDetailStatus, selectCollectedIdSet } from '../../state';
@Component({
selector: 'app-icon-preview-page',
@@ -14,28 +14,45 @@ import { selectCollectedIdSet } from '../../state';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class IconPreviewPage {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
private readonly router = inject(Router);
private readonly details = this.store.selectSignal(selectAreaDetails);
private readonly detailStatus = this.store.selectSignal(selectAreaDetailStatus);
protected readonly status = computed(() => this.detailStatus()[this.areaId()] ?? 'loading');
private readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
readonly areaId = input.required<string>();
readonly id = input.required<string>();
protected readonly landmark = computed(() => this.catalog.landmarkById(this.id()));
protected readonly landmark = computed(() => {
const area = this.details()[this.areaId()];
return area ? findAttraction(area, this.id()) : null;
});
protected readonly collected = computed(() => {
const item = this.landmark();
return item ? this.collectedIds().has(item.id) : false;
return item ? isObtained(item, this.collectedIds()) : false;
});
constructor() {
effect(() => {
const item = this.landmark();
const areaId = this.areaId();
const status = this.detailStatus()[areaId];
if (!item || this.collectedIds().has(item.id)) {
if (this.details()[areaId] || status === 'loading' || status === 'ready') {
return;
}
void this.router.navigate(['/city', item.id], { replaceUrl: true });
this.store.dispatch(GorodarActions.areaRequested({ id: areaId }));
});
effect(() => {
const item = this.landmark();
if (this.status() !== 'ready' || !item || isObtained(item, this.collectedIds())) {
return;
}
void this.router.navigate(['/city', this.areaId(), item.id], { replaceUrl: true });
});
}
}
+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 {