fix and add documents view
This commit is contained in:
@@ -9,13 +9,7 @@ import {
|
||||
type Area,
|
||||
type Attraction,
|
||||
} from '../../areas/area.models';
|
||||
import {
|
||||
GorodarActions,
|
||||
selectAreas,
|
||||
selectAreasError,
|
||||
selectAreasStatus,
|
||||
selectCollectedIdSet,
|
||||
} from '../../state';
|
||||
import { GorodarActions, selectAreas, selectAreasError, selectAreasStatus } from '../../state';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cities-page',
|
||||
@@ -30,10 +24,8 @@ export class CitiesPage {
|
||||
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());
|
||||
return areaOpenedCount(area);
|
||||
}
|
||||
|
||||
protected totalCount(area: Area): number {
|
||||
@@ -41,11 +33,11 @@ export class CitiesPage {
|
||||
}
|
||||
|
||||
protected progress(area: Area): number {
|
||||
return areaProgress(area, this.collectedIds());
|
||||
return areaProgress(area);
|
||||
}
|
||||
|
||||
protected obtained(attraction: Attraction): boolean {
|
||||
return attraction.visited || this.collectedIds().has(attraction.id);
|
||||
return attraction.visited;
|
||||
}
|
||||
|
||||
protected reload(): void {
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
areaProgress,
|
||||
areaTotalCount,
|
||||
findAttraction,
|
||||
isObtained,
|
||||
type Attraction,
|
||||
} from '../../areas/area.models';
|
||||
import { CityMap } from '../../map/city-map/city-map';
|
||||
@@ -26,7 +25,6 @@ import {
|
||||
selectAreaDetailError,
|
||||
selectAreaDetails,
|
||||
selectAreaDetailStatus,
|
||||
selectCollectedIdSet,
|
||||
} from '../../state';
|
||||
|
||||
type CollectionFilter = 'all' | 'open' | 'closed';
|
||||
@@ -53,10 +51,9 @@ export class CityPage {
|
||||
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 = computed(() => {
|
||||
const area = this.area();
|
||||
return area ? areaOpenedCount(area, this.collectedIds()) : 0;
|
||||
return area ? areaOpenedCount(area) : 0;
|
||||
});
|
||||
protected readonly totalCount = computed(() => {
|
||||
const area = this.area();
|
||||
@@ -64,7 +61,7 @@ export class CityPage {
|
||||
});
|
||||
protected readonly progress = computed(() => {
|
||||
const area = this.area();
|
||||
return area ? areaProgress(area, this.collectedIds()) : 0;
|
||||
return area ? areaProgress(area) : 0;
|
||||
});
|
||||
protected readonly closedCount = computed(() => this.totalCount() - this.openedCount());
|
||||
protected readonly mapAttractions = computed(() => {
|
||||
@@ -74,13 +71,12 @@ export class CityPage {
|
||||
protected readonly landmarks = computed(() => {
|
||||
const current = this.area();
|
||||
const items = current ? areaAttractions(current) : [];
|
||||
const ids = this.collectedIds();
|
||||
|
||||
switch (this.filter()) {
|
||||
case 'open':
|
||||
return items.filter((item) => isObtained(item, ids));
|
||||
return items.filter((item) => item.visited);
|
||||
case 'closed':
|
||||
return items.filter((item) => !isObtained(item, ids));
|
||||
return items.filter((item) => !item.visited);
|
||||
default:
|
||||
return items;
|
||||
}
|
||||
@@ -117,13 +113,14 @@ export class CityPage {
|
||||
}
|
||||
|
||||
protected isOpen(attraction: Attraction): boolean {
|
||||
return isObtained(attraction, this.collectedIds());
|
||||
return attraction.visited;
|
||||
}
|
||||
|
||||
protected objectRoute(id: string): string[] {
|
||||
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];
|
||||
return attraction?.visited
|
||||
? ['/city', this.areaId(), id, 'icon']
|
||||
: ['/city', this.areaId(), id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,18 @@
|
||||
@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>
|
||||
<div class="account__actions">
|
||||
<button class="account__action" type="button" aria-label="Документы" (click)="openDocuments()">
|
||||
<app-icon name="document" [size]="22" />
|
||||
</button>
|
||||
<button class="account__action" type="button" aria-label="Выйти" (click)="logout()">
|
||||
<app-icon name="logout" [size]="22" />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
} @else {
|
||||
<header class="account">
|
||||
<button class="account__login" type="button" (click)="login()">Войти</button>
|
||||
</header>
|
||||
}
|
||||
|
||||
@@ -64,4 +73,8 @@
|
||||
} @else {
|
||||
<p class="empty">Пока нет полученных объектов.</p>
|
||||
}
|
||||
|
||||
@if (documentsOpen()) {
|
||||
<app-documents-sheet (dismissed)="closeDocuments()" />
|
||||
}
|
||||
</section>
|
||||
|
||||
@@ -27,7 +27,13 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.account__logout {
|
||||
.account__actions {
|
||||
display: flex;
|
||||
flex: none;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.account__action {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
@@ -35,13 +41,27 @@
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--color-border);
|
||||
border: 0;
|
||||
border-radius: 14px;
|
||||
background: var(--color-surface);
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.account__login {
|
||||
margin-left: auto;
|
||||
height: 44px;
|
||||
padding: 0 16px;
|
||||
border: 0;
|
||||
border-radius: 14px;
|
||||
background: var(--color-primary);
|
||||
color: var(--color-label);
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.page__intro {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { afterNextRender, ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
|
||||
import {
|
||||
afterNextRender,
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
computed,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
@@ -7,23 +14,22 @@ import {
|
||||
areaOpenedCount,
|
||||
areaProgress,
|
||||
areaTotalCount,
|
||||
isObtained,
|
||||
type Attraction,
|
||||
} from '../../areas/area.models';
|
||||
import { DocumentsSheet } from '../../shared/documents-sheet/documents-sheet';
|
||||
import { Icon } from '../../shared/icon/icon';
|
||||
import {
|
||||
GorodarActions,
|
||||
selectAreas,
|
||||
selectAuthEmail,
|
||||
selectAuthenticated,
|
||||
selectCollectedIdSet,
|
||||
selectOpenedCount,
|
||||
selectProfile,
|
||||
} from '../../state';
|
||||
|
||||
@Component({
|
||||
selector: 'app-collections-page',
|
||||
imports: [Icon, RouterLink],
|
||||
imports: [Icon, RouterLink, DocumentsSheet],
|
||||
templateUrl: './collections-page.html',
|
||||
styleUrl: './collections-page.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
@@ -33,26 +39,24 @@ export class CollectionsPage {
|
||||
|
||||
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 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 packs = computed(() => {
|
||||
const ids = this.collectedIds();
|
||||
|
||||
return this.areas()
|
||||
protected readonly documentsOpen = signal(false);
|
||||
protected readonly packs = computed(() =>
|
||||
this.areas()
|
||||
.map((area) => ({
|
||||
area,
|
||||
items: areaAttractions(area).filter((item) => isObtained(item, ids)),
|
||||
opened: areaOpenedCount(area, ids),
|
||||
items: areaAttractions(area).filter((item) => item.visited),
|
||||
opened: areaOpenedCount(area),
|
||||
total: areaTotalCount(area),
|
||||
progress: areaProgress(area, ids),
|
||||
progress: areaProgress(area),
|
||||
}))
|
||||
.filter((pack) => pack.items.length > 0);
|
||||
});
|
||||
.filter((pack) => pack.items.length > 0),
|
||||
);
|
||||
|
||||
constructor() {
|
||||
afterNextRender(() => {
|
||||
@@ -69,12 +73,25 @@ export class CollectionsPage {
|
||||
);
|
||||
|
||||
protected objectRoute(areaId: string, attraction: Attraction): string[] {
|
||||
return isObtained(attraction, this.collectedIds())
|
||||
return attraction.visited
|
||||
? ['/city', areaId, attraction.id, 'icon']
|
||||
: ['/city', areaId, attraction.id];
|
||||
}
|
||||
|
||||
protected openDocuments(): void {
|
||||
this.documentsOpen.set(true);
|
||||
}
|
||||
|
||||
protected closeDocuments(): void {
|
||||
this.documentsOpen.set(false);
|
||||
}
|
||||
|
||||
protected login(): void {
|
||||
this.store.dispatch(GorodarActions.authSheetOpened({ intent: 'collection' }));
|
||||
}
|
||||
|
||||
protected logout(): void {
|
||||
this.documentsOpen.set(false);
|
||||
this.store.dispatch(GorodarActions.logout());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +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 { findAttraction } from '../../areas/area.models';
|
||||
import { CollectSuccess } from '../../claim/collect-success/collect-success';
|
||||
import {
|
||||
GorodarActions,
|
||||
selectAreaDetails,
|
||||
selectAreaDetailStatus,
|
||||
selectCollectedIdSet,
|
||||
} from '../../state';
|
||||
import { GorodarActions, selectAreaDetails, selectAreaDetailStatus } from '../../state';
|
||||
|
||||
@Component({
|
||||
selector: 'app-icon-preview-page',
|
||||
@@ -24,7 +19,6 @@ export class IconPreviewPage {
|
||||
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>();
|
||||
@@ -33,10 +27,7 @@ export class IconPreviewPage {
|
||||
const area = this.details()[this.areaId()];
|
||||
return area ? findAttraction(area, this.id()) : null;
|
||||
});
|
||||
protected readonly collected = computed(() => {
|
||||
const item = this.landmark();
|
||||
return item ? isObtained(item, this.collectedIds()) : false;
|
||||
});
|
||||
protected readonly collected = computed(() => this.landmark()?.visited ?? false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
@@ -53,7 +44,7 @@ export class IconPreviewPage {
|
||||
effect(() => {
|
||||
const item = this.landmark();
|
||||
|
||||
if (this.status() !== 'ready' || !item || isObtained(item, this.collectedIds())) {
|
||||
if (this.status() !== 'ready' || !item || item.visited) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,33 +68,14 @@
|
||||
</section>
|
||||
}
|
||||
|
||||
@if (collected()) {
|
||||
<section>
|
||||
<h2>Ваше фото</h2>
|
||||
<button class="owned-photo" type="button" (click)="openPhoto()">
|
||||
<img
|
||||
[src]="userPhoto() ?? '/assets/illustrations/photo-day.svg'"
|
||||
alt="Ваше фото объекта"
|
||||
/>
|
||||
<span class="owned-photo__badge">
|
||||
<app-icon name="check" [size]="14" />
|
||||
Подтверждено
|
||||
</span>
|
||||
</button>
|
||||
<p class="object__hint">
|
||||
Этот объект уже в вашей коллекции. Повторно его получить нельзя.
|
||||
</p>
|
||||
</section>
|
||||
} @else {
|
||||
<section>
|
||||
<h2>Как забрать</h2>
|
||||
<ol class="steps">
|
||||
<li>Приезжайте на место и найдите объект</li>
|
||||
<li>Нажмите «Забрать» и сфотографируйте объект</li>
|
||||
<li>Получите объект в свою коллекцию</li>
|
||||
</ol>
|
||||
</section>
|
||||
}
|
||||
<section>
|
||||
<h2>Как забрать</h2>
|
||||
<ol class="steps">
|
||||
<li>Приезжайте на место и найдите объект</li>
|
||||
<li>Нажмите «Забрать» и сфотографируйте объект</li>
|
||||
<li>Получите объект в свою коллекцию</li>
|
||||
</ol>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@if (!collected()) {
|
||||
@@ -108,22 +89,6 @@
|
||||
}
|
||||
</article>
|
||||
}
|
||||
|
||||
@if (photoOpen()) {
|
||||
@if (userPhoto(); as image) {
|
||||
<div class="photo-viewer" (click)="closePhoto()">
|
||||
<button
|
||||
class="photo-viewer__close"
|
||||
type="button"
|
||||
aria-label="Закрыть"
|
||||
(click)="closePhoto()"
|
||||
>
|
||||
<app-icon name="chevron-left" [size]="22" />
|
||||
</button>
|
||||
<img [src]="image" alt="Ваше фото объекта" (click)="$event.stopPropagation()" />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
} @else if (status() === 'loading') {
|
||||
<section class="object object--empty">
|
||||
<p>Загружаем…</p>
|
||||
|
||||
@@ -13,12 +13,7 @@ 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 { areaOpenedCount, areaTotalCount, type AreaDetails } from '../../areas/area.models';
|
||||
import { ClaimFlow } from '../../claim/claim-flow/claim-flow';
|
||||
import { AudioGuide } from '../../shared/audio-guide/audio-guide';
|
||||
import { Icon } from '../../shared/icon/icon';
|
||||
@@ -32,7 +27,6 @@ import {
|
||||
selectAuthenticated,
|
||||
selectClaim,
|
||||
selectCollectedAt,
|
||||
selectCollectedIdSet,
|
||||
selectPhotos,
|
||||
} from '../../state';
|
||||
|
||||
@@ -63,28 +57,19 @@ export class MapItemPage {
|
||||
(): 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;
|
||||
return area ? areaOpenedCount(area) : 0;
|
||||
});
|
||||
protected readonly totalCount = computed(() => {
|
||||
const area = this.area();
|
||||
return area ? areaTotalCount(area) : 0;
|
||||
});
|
||||
|
||||
protected readonly collected = computed(() => {
|
||||
const item = this.landmark();
|
||||
return item ? isObtained(item, this.collectedIds()) : false;
|
||||
});
|
||||
|
||||
protected readonly userPhoto = computed(() => {
|
||||
const item = this.landmark();
|
||||
return item ? (this.photos()[item.id] ?? null) : null;
|
||||
});
|
||||
protected readonly collected = computed(() => this.landmark()?.visited ?? false);
|
||||
|
||||
protected readonly collectedLabel = computed(() => {
|
||||
if (!this.collected()) {
|
||||
@@ -111,8 +96,6 @@ export class MapItemPage {
|
||||
return claim.landmarkId === this.id() && claim.stage !== 'idle';
|
||||
});
|
||||
|
||||
protected readonly photoOpen = signal(false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const areaId = this.areaId();
|
||||
@@ -147,19 +130,4 @@ export class MapItemPage {
|
||||
|
||||
this.store.dispatch(GorodarActions.authSheetOpened({ intent: 'claim', landmarkId: this.id() }));
|
||||
}
|
||||
|
||||
protected openPhoto(): void {
|
||||
if (this.userPhoto()) {
|
||||
this.photoOpen.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected closePhoto(): void {
|
||||
this.photoOpen.set(false);
|
||||
}
|
||||
|
||||
@HostListener('document:keydown.escape')
|
||||
protected onEscape(): void {
|
||||
this.closePhoto();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { type CanActivateFn, Router } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { filter, map, take } from 'rxjs';
|
||||
|
||||
import { findAttraction } from '../../areas/area.models';
|
||||
import { GorodarActions, selectAreaDetails } from '../../state';
|
||||
|
||||
export const visitedItemGuard: CanActivateFn = (route) => {
|
||||
const store = inject(Store);
|
||||
const router = inject(Router);
|
||||
const areaId = route.paramMap.get('areaId') ?? '';
|
||||
const id = route.paramMap.get('id') ?? '';
|
||||
|
||||
store.dispatch(GorodarActions.areaRequested({ id: areaId }));
|
||||
|
||||
return store.select(selectAreaDetails).pipe(
|
||||
map((details) => {
|
||||
const area = details[areaId];
|
||||
return area ? findAttraction(area, id) : undefined;
|
||||
}),
|
||||
filter((item) => item !== undefined),
|
||||
take(1),
|
||||
map((item) => (item?.visited ? router.createUrlTree(['/city', areaId]) : true)),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user