diff --git a/public/assets/documents/privacy-policy.pdf b/public/assets/documents/privacy-policy.pdf new file mode 100644 index 0000000..2030f05 Binary files /dev/null and b/public/assets/documents/privacy-policy.pdf differ diff --git a/public/assets/documents/terms-of-use.pdf b/public/assets/documents/terms-of-use.pdf new file mode 100644 index 0000000..c3a9702 Binary files /dev/null and b/public/assets/documents/terms-of-use.pdf differ diff --git a/public/assets/icons/document.svg b/public/assets/icons/document.svg new file mode 100644 index 0000000..79c0bee --- /dev/null +++ b/public/assets/icons/document.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 4fd84c6..776c829 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -5,6 +5,7 @@ import { CityPage } from './pages/city-page/city-page'; import { CollectionsPage } from './pages/collections-page/collections-page'; import { IconPreviewPage } from './pages/icon-preview-page/icon-preview-page'; import { MapItemPage } from './pages/map-item-page/map-item-page'; +import { visitedItemGuard } from './pages/map-item-page/visited-item.guard'; import { MapPage } from './pages/map-page/map-page'; export const routes: Routes = [ @@ -13,7 +14,7 @@ export const routes: Routes = [ { path: 'collections', component: CollectionsPage }, { path: 'collection', pathMatch: 'full', redirectTo: '' }, { path: 'city/:areaId/:id/icon', component: IconPreviewPage }, - { path: 'city/:areaId/:id', component: MapItemPage }, + { path: 'city/:areaId/:id', component: MapItemPage, canActivate: [visitedItemGuard] }, { path: 'city/:areaId', component: CityPage }, { path: '**', redirectTo: '' }, ]; diff --git a/src/app/areas/area.models.ts b/src/app/areas/area.models.ts index 52c7796..e9f492a 100644 --- a/src/app/areas/area.models.ts +++ b/src/app/areas/area.models.ts @@ -65,15 +65,11 @@ export function findAttraction(area: Area | AreaDetails, id: string): Attraction return areaAttractions(area).find((item) => item.id === id) ?? null; } -export function isObtained(attraction: Attraction, collectedIds: ReadonlySet): boolean { - return attraction.visited || collectedIds.has(attraction.id); -} - -export function areaOpenedCount(area: Area | AreaDetails, collectedIds: ReadonlySet): number { +export function areaOpenedCount(area: Area | AreaDetails): number { const attractions = areaAttractions(area); if (attractions.length > 0) { - return attractions.filter((item) => isObtained(item, collectedIds)).length; + return attractions.filter((item) => item.visited).length; } return area.progress?.visited ?? 0; @@ -89,12 +85,12 @@ export function areaTotalCount(area: Area | AreaDetails): number { return area.progress?.total ?? 0; } -export function areaProgress(area: Area | AreaDetails, collectedIds: ReadonlySet): number { +export function areaProgress(area: Area | AreaDetails): number { const total = areaTotalCount(area); if (!total) { return 0; } - return Math.round((areaOpenedCount(area, collectedIds) / total) * 100); + return Math.round((areaOpenedCount(area) / total) * 100); } diff --git a/src/app/auth/ui/auth-sheet/auth-sheet.html b/src/app/auth/ui/auth-sheet/auth-sheet.html index 504ebb5..0b4985d 100644 --- a/src/app/auth/ui/auth-sheet/auth-sheet.html +++ b/src/app/auth/ui/auth-sheet/auth-sheet.html @@ -61,6 +61,12 @@ {{ pending() ? 'Отправляем…' : 'Получить код' }} + } @else {

{{ title() }}

diff --git a/src/app/auth/ui/auth-sheet/auth-sheet.scss b/src/app/auth/ui/auth-sheet/auth-sheet.scss index 0052558..5d0b616 100644 --- a/src/app/auth/ui/auth-sheet/auth-sheet.scss +++ b/src/app/auth/ui/auth-sheet/auth-sheet.scss @@ -73,11 +73,7 @@ .sheet__lock { display: grid; place-items: center; - width: 68px; - height: 68px; margin: 8px auto 16px; - border: 1.5px solid var(--color-accent); - border-radius: 18px; color: var(--color-accent); } @@ -205,6 +201,20 @@ cursor: pointer; } +.sheet__legal { + margin: 8px 0 0; + color: var(--color-muted); + font-size: 12px; + line-height: 1.45; + text-align: center; +} + +.sheet__legal a { + color: var(--color-accent-soft); + text-decoration: underline; + text-underline-offset: 2px; +} + @keyframes sheet-in { from { transform: translateY(24px); diff --git a/src/app/auth/ui/auth-sheet/auth-sheet.ts b/src/app/auth/ui/auth-sheet/auth-sheet.ts index 39b4da4..993afd2 100644 --- a/src/app/auth/ui/auth-sheet/auth-sheet.ts +++ b/src/app/auth/ui/auth-sheet/auth-sheet.ts @@ -14,6 +14,7 @@ import { import { Store } from '@ngrx/store'; import { Icon } from '../../../shared/icon/icon'; +import { privacyDocumentUrl, termsDocumentUrl } from '../../../shared/legal-documents'; import { RESEND_SECONDS } from '../../../state/gorodar.models'; import { GorodarActions, @@ -57,6 +58,8 @@ export class AuthSheet { private dragVelocity = 0; private closeTimer = 0; + protected readonly termsUrl = termsDocumentUrl; + protected readonly privacyUrl = privacyDocumentUrl; protected readonly emailDraft = signal(''); protected readonly digits = signal(emptyDigits()); protected readonly secondsLeft = signal(0); diff --git a/src/app/map/city-map/city-map.ts b/src/app/map/city-map/city-map.ts index 96ccac2..e0a877d 100644 --- a/src/app/map/city-map/city-map.ts +++ b/src/app/map/city-map/city-map.ts @@ -13,11 +13,9 @@ import { signal, } from '@angular/core'; import { Geolocation, type Position } from '@capacitor/geolocation'; -import { Store } from '@ngrx/store'; import type { Attraction } from '../../areas/area.models'; import { Icon } from '../../shared/icon/icon'; -import { selectCollectedIdSet } from '../../state'; import { MapItemSheet } from '../map-item-sheet/map-item-sheet'; const MAP_KEY = 'bf0a466f-43a6-48c7-b274-7fea5952957b'; @@ -136,7 +134,6 @@ export class CityMap implements AfterViewInit, OnDestroy { @ViewChild('map', { static: true }) private mapElement!: ElementRef; - private readonly store = inject(Store); private readonly zone = inject(NgZone); private raster: DgApi | null = null; private map: DgMap | null = null; @@ -154,7 +151,6 @@ export class CityMap implements AfterViewInit, OnDestroy { private readonly markers = new Map(); private readonly mapReady = signal(false); private placedKey = ''; - private readonly collectedIds = this.store.selectSignal(selectCollectedIdSet); private readonly stopFollowing = (): void => { this.programmaticMove = false; this.zone.run(() => this.following.set(false)); @@ -182,13 +178,12 @@ export class CityMap implements AfterViewInit, OnDestroy { constructor() { effect(() => { const items = this.attractions(); - const ids = this.collectedIds(); if (!this.mapReady()) { return; } - this.placeMarkers(items, ids); + this.placeMarkers(items); }); effect(() => { @@ -366,7 +361,7 @@ export class CityMap implements AfterViewInit, OnDestroy { this.watchId = null; } - private placeMarkers(items: Attraction[], collectedIds: Set): void { + private placeMarkers(items: Attraction[]): void { const map = this.map; const api = this.raster; @@ -381,7 +376,7 @@ export class CityMap implements AfterViewInit, OnDestroy { const element = this.markerElements.get(item.id); if (element) { - this.setMarkerIcon(element, collectedIds.has(item.id) || item.visited); + this.setMarkerIcon(element, item); } } @@ -401,10 +396,7 @@ export class CityMap implements AfterViewInit, OnDestroy { continue; } - this.markers.set( - item.id, - this.createMarker(api, map, item, collectedIds.has(item.id) || item.visited), - ); + this.markers.set(item.id, this.createMarker(api, map, item)); } if (this.markers.size > 0) { @@ -412,26 +404,29 @@ export class CityMap implements AfterViewInit, OnDestroy { } } - private createMarker(api: DgApi, map: DgMap, landmark: Attraction, collected: boolean): DgMarker { + private createMarker(api: DgApi, map: DgMap, item: Attraction): DgMarker { const markerElement = document.createElement('button'); markerElement.type = 'button'; markerElement.className = 'city-map__marker'; - markerElement.setAttribute('aria-label', landmark.name); - markerElement.innerHTML = - ''; + markerElement.setAttribute('aria-label', item.name); + markerElement.innerHTML = ``; + // ''; + // Marker with radius + // markerElement.innerHTML = + // ''; const label = markerElement.querySelector('.city-map__label'); if (label) { - label.textContent = landmark.name; + label.textContent = item.name; } - this.markerElements.set(landmark.id, markerElement); - this.setMarkerIcon(markerElement, collected); + this.markerElements.set(item.id, markerElement); + this.setMarkerIcon(markerElement, item); const marker = this.addHtmlMarker( api, map, - [landmark.longitude, landmark.latitude], + [item.longitude, item.latitude], markerElement, LANDMARK_SIZE, 1, @@ -439,7 +434,7 @@ export class CityMap implements AfterViewInit, OnDestroy { ); marker.on('click', () => { - this.zone.run(() => this.selectLandmark(landmark)); + this.zone.run(() => this.selectLandmark(item)); }); return marker; @@ -491,20 +486,20 @@ export class CityMap implements AfterViewInit, OnDestroy { return marker; } - private setMarkerIcon(element: HTMLElement, collected: boolean): void { + private setMarkerIcon(element: HTMLElement, item: Attraction): void { const img = element.querySelector('img'); if (!img) { return; } - const src = collected ? '/assets/icons/check-marker.svg' : '/assets/icons/lock-marker.svg'; + const src = item.visited ? '/assets/icons/check-marker.svg' : '/assets/icons/lock-marker.svg'; if (img.getAttribute('src') !== src) { img.setAttribute('src', src); } - element.classList.toggle('city-map__marker--open', collected); + element.classList.toggle('city-map__marker--open', item.visited); } private selectLandmark(landmark: Attraction): void { diff --git a/src/app/map/map-item-sheet/map-item-sheet.html b/src/app/map/map-item-sheet/map-item-sheet.html index cacc64d..8298323 100644 --- a/src/app/map/map-item-sheet/map-item-sheet.html +++ b/src/app/map/map-item-sheet/map-item-sheet.html @@ -1,8 +1,9 @@

diff --git a/src/app/map/map-item-sheet/map-item-sheet.scss b/src/app/map/map-item-sheet/map-item-sheet.scss index 4a26da8..475e8d4 100644 --- a/src/app/map/map-item-sheet/map-item-sheet.scss +++ b/src/app/map/map-item-sheet/map-item-sheet.scss @@ -15,7 +15,6 @@ display: flex; align-items: flex-start; gap: 14px; - margin-bottom: 16px; } .card__stamp { @@ -51,4 +50,3 @@ color: var(--color-success); font-weight: 500; } - diff --git a/src/app/pages/cities-page/cities-page.ts b/src/app/pages/cities-page/cities-page.ts index 10d7b48..afaefca 100644 --- a/src/app/pages/cities-page/cities-page.ts +++ b/src/app/pages/cities-page/cities-page.ts @@ -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 { diff --git a/src/app/pages/city-page/city-page.ts b/src/app/pages/city-page/city-page.ts index 905a975..5e75fe9 100644 --- a/src/app/pages/city-page/city-page.ts +++ b/src/app/pages/city-page/city-page.ts @@ -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('objects'); protected readonly mapReady = signal(false); protected readonly filter = signal('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]; } } diff --git a/src/app/pages/collections-page/collections-page.html b/src/app/pages/collections-page/collections-page.html index ff89bdb..d82c830 100644 --- a/src/app/pages/collections-page/collections-page.html +++ b/src/app/pages/collections-page/collections-page.html @@ -2,9 +2,18 @@ @if (authenticated()) { + } @else { + } @@ -64,4 +73,8 @@ } @else {

Пока нет полученных объектов.

} + + @if (documentsOpen()) { + + } diff --git a/src/app/pages/collections-page/collections-page.scss b/src/app/pages/collections-page/collections-page.scss index 5d3438d..0aeaea1 100644 --- a/src/app/pages/collections-page/collections-page.scss +++ b/src/app/pages/collections-page/collections-page.scss @@ -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; } diff --git a/src/app/pages/collections-page/collections-page.ts b/src/app/pages/collections-page/collections-page.ts index 450cf6d..9f26f39 100644 --- a/src/app/pages/collections-page/collections-page.ts +++ b/src/app/pages/collections-page/collections-page.ts @@ -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()); } diff --git a/src/app/pages/icon-preview-page/icon-preview-page.ts b/src/app/pages/icon-preview-page/icon-preview-page.ts index dffa4c0..4c78d7a 100644 --- a/src/app/pages/icon-preview-page/icon-preview-page.ts +++ b/src/app/pages/icon-preview-page/icon-preview-page.ts @@ -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(); readonly id = input.required(); @@ -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; } diff --git a/src/app/pages/map-item-page/map-item-page.html b/src/app/pages/map-item-page/map-item-page.html index ae33ed4..db38e19 100644 --- a/src/app/pages/map-item-page/map-item-page.html +++ b/src/app/pages/map-item-page/map-item-page.html @@ -68,33 +68,14 @@ } - @if (collected()) { -
-

Ваше фото

- -

- Этот объект уже в вашей коллекции. Повторно его получить нельзя. -

-
- } @else { -
-

Как забрать

-
    -
  1. Приезжайте на место и найдите объект
  2. -
  3. Нажмите «Забрать» и сфотографируйте объект
  4. -
  5. Получите объект в свою коллекцию
  6. -
-
- } +
+

Как забрать

+
    +
  1. Приезжайте на место и найдите объект
  2. +
  3. Нажмите «Забрать» и сфотографируйте объект
  4. +
  5. Получите объект в свою коллекцию
  6. +
+
@if (!collected()) { @@ -108,22 +89,6 @@ } } - - @if (photoOpen()) { - @if (userPhoto(); as image) { -
- - Ваше фото объекта -
- } - } } @else if (status() === 'loading') {

Загружаем…

diff --git a/src/app/pages/map-item-page/map-item-page.ts b/src/app/pages/map-item-page/map-item-page.ts index 9475975..171d071 100644 --- a/src/app/pages/map-item-page/map-item-page.ts +++ b/src/app/pages/map-item-page/map-item-page.ts @@ -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(); - } } diff --git a/src/app/pages/map-item-page/visited-item.guard.ts b/src/app/pages/map-item-page/visited-item.guard.ts new file mode 100644 index 0000000..6d6a018 --- /dev/null +++ b/src/app/pages/map-item-page/visited-item.guard.ts @@ -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)), + ); +}; diff --git a/src/app/shared/documents-sheet/documents-sheet.html b/src/app/shared/documents-sheet/documents-sheet.html new file mode 100644 index 0000000..9e20871 --- /dev/null +++ b/src/app/shared/documents-sheet/documents-sheet.html @@ -0,0 +1,41 @@ +
+ + +
+ +
+
diff --git a/src/app/shared/documents-sheet/documents-sheet.scss b/src/app/shared/documents-sheet/documents-sheet.scss new file mode 100644 index 0000000..bae0c70 --- /dev/null +++ b/src/app/shared/documents-sheet/documents-sheet.scss @@ -0,0 +1,132 @@ +:host { + display: contents; +} + +.sheet-root { + position: fixed; + z-index: 70; + inset: 0; + display: flex; + align-items: flex-end; + justify-content: center; +} + +.sheet-root__backdrop { + position: absolute; + inset: 0; + border: 0; + background: rgb(8 7 6 / 64%); + cursor: pointer; + opacity: calc(1 - min(var(--drag-y, 0px), 280px) / 280px); +} + +.sheet-pop { + position: relative; + z-index: 1; + width: min(100%, 480px); + max-height: min(92dvh, 760px); + animation: sheet-in 0.28s ease-out; +} + +.sheet { + width: 100%; + max-height: min(92dvh, 760px); + overflow: hidden auto; + padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); + border: 1px solid var(--color-border); + border-bottom: 0; + border-radius: 28px 28px 0 0; + background: #1a1815; + transform: translateY(var(--drag-y, 0px)); + transition: transform 0.22s ease-out; + touch-action: pan-y; +} + +.sheet--dragging { + overflow: hidden; + transition: none; + touch-action: none; +} + +.sheet__handle { + display: block; + width: 100%; + height: 28px; + margin: 0 auto 4px; + padding: 10px 0 12px; + border: 0; + background: transparent; + cursor: grab; + touch-action: none; +} + +.sheet__handle::before { + content: ''; + display: block; + width: 42px; + height: 4px; + margin: 0 auto; + border-radius: 4px; + background: #4a453c; +} + +.sheet__mark { + display: grid; + place-items: center; + margin: 8px auto 16px; + color: var(--color-accent); +} + +.sheet h2 { + margin: 0; + font-family: var(--font-display); + font-size: clamp(26px, 7vw, 32px); + font-weight: 700; + line-height: 1.15; + text-align: center; +} + +.docs { + display: flex; + flex-direction: column; + gap: 10px; + margin: 20px 0 0; + padding: 0; + list-style: none; +} + +.docs a { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + min-height: 56px; + padding: 12px 14px; + border: 1px solid var(--color-border); + border-radius: 16px; + background: #12110f; + color: var(--color-text); + font-size: 15px; + font-weight: 600; + line-height: 1.3; + text-decoration: none; +} + +@keyframes sheet-in { + from { + transform: translateY(24px); + } + to { + transform: translateY(0); + } +} + +@media (prefers-reduced-motion: reduce) { + .sheet-pop { + animation: none; + } + + .sheet { + transition: none; + } +} diff --git a/src/app/shared/documents-sheet/documents-sheet.ts b/src/app/shared/documents-sheet/documents-sheet.ts new file mode 100644 index 0000000..8c8622a --- /dev/null +++ b/src/app/shared/documents-sheet/documents-sheet.ts @@ -0,0 +1,168 @@ +import { + ChangeDetectionStrategy, + Component, + DestroyRef, + HostListener, + inject, + output, + signal, +} from '@angular/core'; + +import { Icon } from '../icon/icon'; +import { legalDocuments } from '../legal-documents'; + +const DISMISS_DISTANCE = 120; +const DISMISS_VELOCITY = 0.55; + +@Component({ + selector: 'app-documents-sheet', + imports: [Icon], + templateUrl: './documents-sheet.html', + styleUrl: './documents-sheet.scss', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class DocumentsSheet { + private readonly destroyRef = inject(DestroyRef); + private pointerId: number | null = null; + private dragOriginY = 0; + private dragOriginX = 0; + private dragScrollTop = 0; + private dragFromHandle = false; + private dragTracking = false; + private dragMoved = false; + private dragLastY = 0; + private dragLastTime = 0; + private dragVelocity = 0; + private closeTimer = 0; + + protected readonly documents = legalDocuments; + protected readonly dragY = signal(0); + protected readonly dragging = signal(false); + + readonly dismissed = output(); + + constructor() { + this.destroyRef.onDestroy(() => window.clearTimeout(this.closeTimer)); + } + + protected dismiss(): void { + window.clearTimeout(this.closeTimer); + this.closeTimer = 0; + this.dragY.set(0); + this.dragging.set(false); + this.dismissed.emit(); + } + + protected onDragStart(event: PointerEvent): void { + if (!event.isPrimary || event.button !== 0 || !this.canDragFrom(event.target)) { + return; + } + + const sheet = event.currentTarget as HTMLElement; + this.pointerId = event.pointerId; + this.dragOriginY = event.clientY; + this.dragOriginX = event.clientX; + this.dragScrollTop = sheet.scrollTop; + this.dragFromHandle = this.isHandle(event.target); + this.dragTracking = false; + this.dragMoved = false; + this.dragLastY = event.clientY; + this.dragLastTime = event.timeStamp; + this.dragVelocity = 0; + } + + protected onDragMove(event: PointerEvent): void { + if (event.pointerId !== this.pointerId) { + return; + } + + const dy = event.clientY - this.dragOriginY; + const dx = event.clientX - this.dragOriginX; + const sheet = event.currentTarget as HTMLElement; + + if (!this.dragTracking) { + if (Math.abs(dy) < 8 && Math.abs(dx) < 8) { + return; + } + + const pullingDown = dy > 0 && Math.abs(dy) > Math.abs(dx); + const atTop = this.dragScrollTop <= 0; + + if (!pullingDown || (!atTop && !this.dragFromHandle)) { + this.pointerId = null; + return; + } + + this.dragTracking = true; + this.dragMoved = true; + this.dragging.set(true); + sheet.setPointerCapture(event.pointerId); + } + + const elapsed = event.timeStamp - this.dragLastTime; + + if (elapsed > 0) { + this.dragVelocity = (event.clientY - this.dragLastY) / elapsed; + } + + this.dragLastY = event.clientY; + this.dragLastTime = event.timeStamp; + this.dragY.set(Math.max(0, dy)); + } + + protected onDragEnd(event: PointerEvent): void { + if (event.pointerId !== this.pointerId) { + return; + } + + const sheet = event.currentTarget as HTMLElement; + const offset = this.dragY(); + const close = + event.type !== 'pointercancel' && + this.dragTracking && + (offset > DISMISS_DISTANCE || (offset > 48 && this.dragVelocity > DISMISS_VELOCITY)); + + this.pointerId = null; + this.dragTracking = false; + this.dragging.set(false); + + if (this.dragMoved) { + const stopClick = (clickEvent: Event): void => { + clickEvent.preventDefault(); + clickEvent.stopPropagation(); + }; + sheet.addEventListener('click', stopClick, { capture: true, once: true }); + this.dragMoved = false; + } + + if (!close) { + this.dragY.set(0); + return; + } + + this.dragY.set(sheet.getBoundingClientRect().height); + window.clearTimeout(this.closeTimer); + this.closeTimer = window.setTimeout(() => this.dismiss(), 200); + } + + @HostListener('document:keydown.escape') + protected onEscape(): void { + this.dismiss(); + } + + private canDragFrom(target: EventTarget | null): boolean { + if (!(target instanceof Element)) { + return true; + } + + if (this.isHandle(target)) { + return true; + } + + return target.closest('a, button') == null; + } + + private isHandle(target: EventTarget | null): boolean { + return target instanceof Element && target.closest('.sheet__handle') != null; + } +} diff --git a/src/app/shared/legal-documents.ts b/src/app/shared/legal-documents.ts new file mode 100644 index 0000000..03e990a --- /dev/null +++ b/src/app/shared/legal-documents.ts @@ -0,0 +1,7 @@ +export const termsDocumentUrl = '/assets/documents/terms-of-use.pdf'; +export const privacyDocumentUrl = '/assets/documents/privacy-policy.pdf'; + +export const legalDocuments = [ + { title: 'Пользовательское соглашение', href: termsDocumentUrl }, + { title: 'Политика обработки персональных данных', href: privacyDocumentUrl }, +] as const; diff --git a/src/app/state/gorodar.models.ts b/src/app/state/gorodar.models.ts index ff53bdd..f560388 100644 --- a/src/app/state/gorodar.models.ts +++ b/src/app/state/gorodar.models.ts @@ -42,7 +42,6 @@ export interface AuthState { } export interface GorodarState { - collectedIds: string[]; photos: Record; collectedAt: Record; claim: ClaimState; diff --git a/src/app/state/gorodar.reducer.ts b/src/app/state/gorodar.reducer.ts index 9de43b0..5b63cfa 100644 --- a/src/app/state/gorodar.reducer.ts +++ b/src/app/state/gorodar.reducer.ts @@ -2,6 +2,7 @@ import { createFeature, createReducer, on } from '@ngrx/store'; import { areaAttractions, + type Area, type AreaDetails, type AreaProgress, type Attraction, @@ -42,7 +43,6 @@ const restoredAuth: AuthState = { }; export const initialState: GorodarState = { - collectedIds: [], photos: {}, collectedAt: {}, claim: initialClaim, @@ -87,9 +87,7 @@ const gorodarReducer = createReducer( GorodarActions.claimCompleted, (state, { landmarkId, photo, collectedAt, alreadyVisited, progress }): GorodarState => ({ ...state, - collectedIds: state.collectedIds.includes(landmarkId) - ? state.collectedIds - : [...state.collectedIds, landmarkId], + areas: markListVisited(state.areas, landmarkId, progress), photos: { ...state.photos, [landmarkId]: photo, @@ -268,7 +266,6 @@ const gorodarReducer = createReducer( GorodarActions.logout, (state): GorodarState => ({ ...state, - collectedIds: [], photos: {}, collectedAt: {}, claim: initialClaim, @@ -408,6 +405,22 @@ function markVisited(item: Attraction, id: string): Attraction { return item.id === id ? { ...item, visited: true } : item; } +function markListVisited(areas: Area[], landmarkId: string, progress: AreaProgress): Area[] { + return areas.map((area) => { + const attractions = area.attractions ?? []; + + if (!attractions.some((item) => item.id === landmarkId)) { + return area; + } + + return { + ...area, + progress: progress ?? area.progress, + attractions: attractions.map((item) => markVisited(item, landmarkId)), + }; + }); +} + function markAreaVisited( details: Record, landmarkId: string, diff --git a/src/app/state/gorodar.selectors.ts b/src/app/state/gorodar.selectors.ts index 0db9c29..ce6ad30 100644 --- a/src/app/state/gorodar.selectors.ts +++ b/src/app/state/gorodar.selectors.ts @@ -4,7 +4,6 @@ import { areaOpenedCount, areaTotalCount, type Area, type AreaDetails } from '.. import { gorodarFeature } from './gorodar.reducer'; export const { - selectCollectedIds, selectPhotos, selectCollectedAt, selectClaim, @@ -21,14 +20,8 @@ export const { selectAttractionError, } = gorodarFeature; -export const selectCollectedIdSet = createSelector(selectCollectedIds, (ids) => new Set(ids)); - -export const selectOpenedCount = createSelector( - selectAreas, - selectAreaDetails, - selectCollectedIdSet, - (areas, details, ids) => - areas.reduce((sum, area) => sum + areaOpenedCount(resolveArea(area, details), ids), 0), +export const selectOpenedCount = createSelector(selectAreas, selectAreaDetails, (areas, details) => + areas.reduce((sum, area) => sum + areaOpenedCount(resolveArea(area, details)), 0), ); export const selectTotalCount = createSelector(selectAreas, selectAreaDetails, (areas, details) => diff --git a/src/assets/styles/_map.scss b/src/assets/styles/_map.scss index 39a7ccc..fa9c416 100644 --- a/src/assets/styles/_map.scss +++ b/src/assets/styles/_map.scss @@ -54,7 +54,7 @@ .city-map__label { position: absolute; left: 50%; - bottom: calc(50% + (var(--radius-px, 80px) / 2) + 6px); + bottom: calc(20% + (var(--radius-px, 80px) / 2) + 6px); display: none; padding: 0 4px; color: var(--color-text); diff --git a/src/assets/styles/_object.scss b/src/assets/styles/_object.scss index 3a78308..57c76a6 100644 --- a/src/assets/styles/_object.scss +++ b/src/assets/styles/_object.scss @@ -26,75 +26,3 @@ height: 120px; background: linear-gradient(to bottom, transparent, var(--color-bg)); } - -.owned-photo { - position: relative; - display: block; - width: 100%; - height: 220px; - padding: 0; - overflow: hidden; - border: 1px solid var(--color-accent-strong); - border-radius: 16px; - background: var(--color-surface); - cursor: zoom-in; -} - -.owned-photo img { - display: block; - width: 100%; - height: 100%; - object-fit: cover; -} - -.owned-photo__badge { - position: absolute; - left: 12px; - bottom: 12px; - display: inline-flex; - align-items: center; - gap: 6px; - padding: 5px 11px; - overflow: visible; - border-radius: 10px; - background: rgb(18 17 15 / 82%); - color: var(--color-accent-soft); - font-size: 13px; - font-weight: 500; - line-height: 1; -} - -.photo-viewer { - position: fixed; - inset: 0; - z-index: 40; - display: flex; - align-items: center; - justify-content: center; - padding: 56px 16px 24px; - background: rgb(18 17 15 / 94%); -} - -.photo-viewer img { - display: block; - max-width: 100%; - max-height: 100%; - object-fit: contain; - border-radius: 12px; -} - -.photo-viewer__close { - position: absolute; - top: 16px; - left: 16px; - display: flex; - align-items: center; - justify-content: center; - width: 44px; - height: 44px; - border: 1px solid var(--color-border); - border-radius: 14px; - background: rgb(28 26 23 / 86%); - color: var(--color-text); - cursor: pointer; -}