-
{{ item.title }}
+
{{ item.name }}
@@ -21,39 +29,44 @@
-
-
-
-
{{ item.address }}
-
{{ item.addressHint }}
+ @if (item.address) {
+
-
+ }
-
- О месте
- {{ item.description }}
-
+ @if (item.about) {
+
+ О месте
+ {{ item.about }}
+
+ }
-
+ @if (item.facts.length > 0) {
+
+ Интересные факты
+
+ @for (fact of item.facts; track fact; let index = $index) {
+ -
+ {{ index + 1 }}
+ {{ fact }}
+
+ }
+
+
+ }
-
- Интересные факты
-
- @for (fact of item.facts; track fact; let index = $index) {
- -
- {{ index + 1 }}
-
- {{ fact }}
-
-
- }
-
-
+ @if (item.audioUrl) {
+
+ }
@if (collected()) {
}
}
+} @else if (status() === 'loading') {
+
} @else {
- Объект не найден.
+ {{ error() || 'Объект не найден.' }}
}
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 fd15c81..6653017 100644
--- a/src/app/pages/map-item-page/map-item-page.ts
+++ b/src/app/pages/map-item-page/map-item-page.ts
@@ -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
();
readonly id = input.required();
- 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 {
diff --git a/src/app/root/services/city-catalog.service.ts b/src/app/root/services/city-catalog.service.ts
deleted file mode 100644
index c32640a..0000000
--- a/src/app/root/services/city-catalog.service.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { Injectable } from '@angular/core';
-
-import { NIZHNY_NOVGOROD, type City, type Landmark } from '../../data/nizhny-novgorod';
-
-@Injectable({
- providedIn: 'root',
-})
-export class CityCatalogService {
- readonly city: City = NIZHNY_NOVGOROD;
-
- landmarkById(id: string): Landmark | undefined {
- return this.city.objects.find((item) => item.id === id);
- }
-}
diff --git a/src/app/state/areas.effects.ts b/src/app/state/areas.effects.ts
new file mode 100644
index 0000000..f4399ba
--- /dev/null
+++ b/src/app/state/areas.effects.ts
@@ -0,0 +1,62 @@
+import { Injectable, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { catchError, map, mergeMap, of, switchMap } from 'rxjs';
+
+import { AreasApiService } from '../areas/areas-api.service';
+import { authErrorMessage } from '../auth/auth-error';
+import { GorodarActions } from './gorodar.actions';
+
+@Injectable()
+export class AreasEffects {
+ private readonly actions$ = inject(Actions);
+ private readonly api = inject(AreasApiService);
+
+ readonly loadAreas$ = createEffect(() =>
+ this.actions$.pipe(
+ ofType(GorodarActions.areasRequested),
+ switchMap(() =>
+ this.api.getAreas().pipe(
+ map((areas) => GorodarActions.areasLoaded({ areas })),
+ catchError((error: unknown) =>
+ of(GorodarActions.areasFailed({ error: authErrorMessage(error) })),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ readonly loadArea$ = createEffect(() =>
+ this.actions$.pipe(
+ ofType(GorodarActions.areaRequested),
+ mergeMap(({ id }) =>
+ this.api.getArea(id).pipe(
+ map((area) => GorodarActions.areaLoaded({ area })),
+ catchError((error: unknown) =>
+ of(GorodarActions.areaFailed({ id, error: authErrorMessage(error) })),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ readonly loadAttraction$ = createEffect(() =>
+ this.actions$.pipe(
+ ofType(GorodarActions.attractionRequested),
+ mergeMap(({ id }) =>
+ this.api.getAttraction(id).pipe(
+ map((attraction) => GorodarActions.attractionLoaded({ attraction })),
+ catchError((error: unknown) =>
+ of(GorodarActions.attractionFailed({ id, error: authErrorMessage(error) })),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ readonly reloadAreas$ = createEffect(() =>
+ this.actions$.pipe(
+ ofType(GorodarActions.authCodeConfirmSucceeded, GorodarActions.logout),
+ map(() => GorodarActions.areasRequested()),
+ ),
+ );
+}
diff --git a/src/app/state/gorodar.actions.ts b/src/app/state/gorodar.actions.ts
index 56c47f5..81de82c 100644
--- a/src/app/state/gorodar.actions.ts
+++ b/src/app/state/gorodar.actions.ts
@@ -1,5 +1,8 @@
import { createActionGroup, emptyProps, props } from '@ngrx/store';
+import type { Area, AreaDetails, AreaProgress, AttractionDetails } from '../areas/area.models';
+import type { ClaimFailure } from './gorodar.models';
+
export const GorodarActions = createActionGroup({
source: 'Gorodar',
events: {
@@ -7,7 +10,14 @@ export const GorodarActions = createActionGroup({
'Photo Captured': props<{ landmarkId: string; photo: string }>(),
'Photo Cancelled': emptyProps(),
'Claim Step Changed': props<{ step: number }>(),
- 'Claim Completed': props<{ landmarkId: string; photo: string; collectedAt: string }>(),
+ 'Claim Completed': props<{
+ landmarkId: string;
+ photo: string;
+ collectedAt: string;
+ alreadyVisited: boolean;
+ progress: AreaProgress;
+ }>(),
+ 'Claim Failed': props<{ failure: ClaimFailure; confidence: number | null }>(),
'Claim Reset': emptyProps(),
'Auth Sheet Opened': props<{ intent: 'claim' | 'collection'; landmarkId?: string }>(),
'Auth Sheet Dismissed': emptyProps(),
@@ -28,5 +38,14 @@ export const GorodarActions = createActionGroup({
'Auth Code Confirm Failed': props<{ error: string }>(),
'Auth Resend Ticked': props<{ seconds: number }>(),
Logout: emptyProps(),
+ 'Areas Requested': emptyProps(),
+ 'Areas Loaded': props<{ areas: Area[] }>(),
+ 'Areas Failed': props<{ error: string }>(),
+ 'Area Requested': props<{ id: string }>(),
+ 'Area Loaded': props<{ area: AreaDetails }>(),
+ 'Area Failed': props<{ id: string; error: string }>(),
+ 'Attraction Requested': props<{ id: string }>(),
+ 'Attraction Loaded': props<{ attraction: AttractionDetails }>(),
+ 'Attraction Failed': props<{ id: string; error: string }>(),
},
});
diff --git a/src/app/state/gorodar.effects.ts b/src/app/state/gorodar.effects.ts
index fca8eb8..6b9853f 100644
--- a/src/app/state/gorodar.effects.ts
+++ b/src/app/state/gorodar.effects.ts
@@ -1,14 +1,33 @@
import { inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
-import { catchError, concat, delay, exhaustMap, from, map, of, switchMap, takeUntil } from 'rxjs';
+import {
+ catchError,
+ EMPTY,
+ exhaustMap,
+ from,
+ map,
+ merge,
+ of,
+ shareReplay,
+ switchMap,
+ take,
+ takeUntil,
+ timer,
+} from 'rxjs';
+import { AreasApiService } from '../areas/areas-api.service';
+import type { VisitResult } from '../areas/area.models';
+import { resizePhoto } from '../areas/resize-photo';
import { CameraService } from '../root/services/camera.service';
import { GorodarActions } from './gorodar.actions';
+const COMPARE_MS = 6_000;
+
@Injectable()
export class GorodarEffects {
private readonly actions$ = inject(Actions);
private readonly camera = inject(CameraService);
+ private readonly areasApi = inject(AreasApiService);
readonly takePhoto$ = createEffect(() =>
this.actions$.pipe(
@@ -29,19 +48,57 @@ export class GorodarEffects {
readonly runCheck$ = createEffect(() =>
this.actions$.pipe(
ofType(GorodarActions.photoCaptured),
- switchMap(({ landmarkId, photo }) =>
- concat(
- of(GorodarActions.claimStepChanged({ step: 2 })).pipe(delay(6_000)),
- of(GorodarActions.claimStepChanged({ step: 3 })).pipe(delay(3_000)),
- of(
- GorodarActions.claimCompleted({
- landmarkId,
- photo,
- collectedAt: new Date().toISOString(),
- }),
- ).pipe(delay(1_000)),
- ).pipe(takeUntil(this.actions$.pipe(ofType(GorodarActions.claimReset)))),
- ),
+ switchMap(({ landmarkId, photo }) => {
+ const visit$ = from(resizePhoto(photo)).pipe(
+ switchMap((file) => this.areasApi.visit(landmarkId, file)),
+ takeUntil(this.actions$.pipe(ofType(GorodarActions.claimReset))),
+ shareReplay({ bufferSize: 1, refCount: false }),
+ );
+
+ const answered$ = visit$.pipe(
+ take(1),
+ catchError(() => of(null)),
+ );
+
+ return merge(
+ timer(COMPARE_MS).pipe(
+ map(() => GorodarActions.claimStepChanged({ step: 2 })),
+ takeUntil(answered$),
+ ),
+ visit$.pipe(
+ take(1),
+ switchMap((result) => this.finishVisit(landmarkId, photo, result)),
+ catchError(() => of(GorodarActions.claimFailed({ failure: 'not_matched', confidence: null }))),
+ ),
+ ).pipe(takeUntil(this.actions$.pipe(ofType(GorodarActions.claimReset))));
+ }),
),
);
+
+ private finishVisit(landmarkId: string, photo: string, result: VisitResult) {
+ if (result.status !== 'VISITED' && result.status !== 'ALREADY_VISITED') {
+ return of(
+ GorodarActions.claimFailed({
+ failure: result.status === 'UNCERTAIN' ? 'uncertain' : 'not_matched',
+ confidence: result.confidence,
+ }),
+ );
+ }
+
+ const completed = GorodarActions.claimCompleted({
+ landmarkId,
+ photo,
+ collectedAt: new Date().toISOString(),
+ alreadyVisited: result.status === 'ALREADY_VISITED',
+ progress: result.progress,
+ });
+
+ return merge(
+ of(GorodarActions.claimStepChanged({ step: 3 }), completed),
+ this.areasApi.getAttraction(landmarkId).pipe(
+ map((attraction) => GorodarActions.attractionLoaded({ attraction })),
+ catchError(() => EMPTY),
+ ),
+ );
+ }
}
diff --git a/src/app/state/gorodar.models.ts b/src/app/state/gorodar.models.ts
index dca3495..ff53bdd 100644
--- a/src/app/state/gorodar.models.ts
+++ b/src/app/state/gorodar.models.ts
@@ -1,12 +1,17 @@
+import type { Area, AreaDetails, AreasStatus, AttractionDetails } from '../areas/area.models';
import type { AuthIntent, AuthSession, AuthStep } from '../auth/auth.models';
-export type ClaimStage = 'idle' | 'check' | 'success';
+export type ClaimStage = 'idle' | 'check' | 'success' | 'failed';
+export type ClaimFailure = 'not_matched' | 'uncertain';
export interface ClaimState {
landmarkId: string | null;
photo: string | null;
stage: ClaimStage;
step: number;
+ failure: ClaimFailure | null;
+ confidence: number | null;
+ alreadyVisited: boolean;
}
export interface ProfileState {
@@ -43,6 +48,15 @@ export interface GorodarState {
claim: ClaimState;
profile: ProfileState;
auth: AuthState;
+ areas: Area[];
+ areasStatus: AreasStatus;
+ areasError: string;
+ areaDetails: Record;
+ areaDetailStatus: Record;
+ areaDetailError: Record;
+ attractions: Record;
+ attractionStatus: Record;
+ attractionError: Record;
}
export const RESEND_SECONDS = 60;
diff --git a/src/app/state/gorodar.reducer.ts b/src/app/state/gorodar.reducer.ts
index 0e47e7f..9de43b0 100644
--- a/src/app/state/gorodar.reducer.ts
+++ b/src/app/state/gorodar.reducer.ts
@@ -1,5 +1,12 @@
import { createFeature, createReducer, on } from '@ngrx/store';
+import {
+ areaAttractions,
+ type AreaDetails,
+ type AreaProgress,
+ type Attraction,
+ type AttractionDetails,
+} from '../areas/area.models';
import { readAuthSession } from '../auth/auth-session';
import { GorodarActions } from './gorodar.actions';
import { RESEND_SECONDS, sessionToAuth, type AuthState, type ClaimState, type GorodarState } from './gorodar.models';
@@ -8,7 +15,10 @@ const initialClaim: ClaimState = {
landmarkId: null,
photo: null,
stage: 'idle',
- step: 1,
+ step: 0,
+ failure: null,
+ confidence: null,
+ alreadyVisited: false,
};
const blankAuth: AuthState = {
@@ -46,6 +56,15 @@ export const initialState: GorodarState = {
phone: '+7 900 123-45-67',
joinedLabel: 'Сентябрь 2026',
},
+ areas: [],
+ areasStatus: 'loading',
+ areasError: '',
+ areaDetails: {},
+ areaDetailStatus: {},
+ areaDetailError: {},
+ attractions: {},
+ attractionStatus: {},
+ attractionError: {},
};
const gorodarReducer = createReducer(
@@ -54,27 +73,19 @@ const gorodarReducer = createReducer(
GorodarActions.photoCaptured,
(state, { landmarkId, photo }): GorodarState => ({
...state,
- claim: {
- landmarkId,
- photo,
- stage: 'check',
- step: 1,
- },
+ claim: { ...initialClaim, landmarkId, photo, stage: 'check', step: 1 },
}),
),
on(
GorodarActions.claimStepChanged,
(state, { step }): GorodarState => ({
...state,
- claim: {
- ...state.claim,
- step,
- },
+ claim: { ...state.claim, step },
}),
),
on(
GorodarActions.claimCompleted,
- (state, { landmarkId, photo, collectedAt }): GorodarState => ({
+ (state, { landmarkId, photo, collectedAt, alreadyVisited, progress }): GorodarState => ({
...state,
collectedIds: state.collectedIds.includes(landmarkId)
? state.collectedIds
@@ -87,12 +98,16 @@ const gorodarReducer = createReducer(
...state.collectedAt,
[landmarkId]: collectedAt,
},
- claim: {
- landmarkId,
- photo,
- stage: 'success',
- step: 3,
- },
+ areaDetails: markAreaVisited(state.areaDetails, landmarkId, progress),
+ attractions: markAttractionVisited(state.attractions, landmarkId),
+ claim: { ...initialClaim, landmarkId, photo, stage: 'success', step: 3, alreadyVisited },
+ }),
+ ),
+ on(
+ GorodarActions.claimFailed,
+ (state, { failure, confidence }): GorodarState => ({
+ ...state,
+ claim: { ...state.claim, stage: 'failed', failure, confidence },
}),
),
on(
@@ -253,15 +268,194 @@ const gorodarReducer = createReducer(
GorodarActions.logout,
(state): GorodarState => ({
...state,
+ collectedIds: [],
+ photos: {},
+ collectedAt: {},
+ claim: initialClaim,
auth: blankAuth,
profile: {
...state.profile,
email: '',
},
+ areaDetails: {},
+ areaDetailStatus: {},
+ areaDetailError: {},
+ attractions: {},
+ attractionStatus: {},
+ attractionError: {},
+ }),
+ ),
+ on(
+ GorodarActions.areasRequested,
+ (state): GorodarState => ({
+ ...state,
+ areasStatus: 'loading',
+ areasError: '',
+ }),
+ ),
+ on(
+ GorodarActions.areasLoaded,
+ (state, { areas }): GorodarState => ({
+ ...state,
+ areas,
+ areasStatus: 'ready',
+ areasError: '',
+ }),
+ ),
+ on(
+ GorodarActions.areasFailed,
+ (state, { error }): GorodarState => ({
+ ...state,
+ areasStatus: 'error',
+ areasError: error,
+ }),
+ ),
+ on(
+ GorodarActions.areaRequested,
+ (state, { id }): GorodarState => ({
+ ...state,
+ areaDetailStatus: {
+ ...state.areaDetailStatus,
+ [id]: 'loading',
+ },
+ areaDetailError: {
+ ...state.areaDetailError,
+ [id]: '',
+ },
+ }),
+ ),
+ on(
+ GorodarActions.areaLoaded,
+ (state, { area }): GorodarState => ({
+ ...state,
+ areaDetails: {
+ ...state.areaDetails,
+ [area.id]: area,
+ },
+ areaDetailStatus: {
+ ...state.areaDetailStatus,
+ [area.id]: 'ready',
+ },
+ areaDetailError: {
+ ...state.areaDetailError,
+ [area.id]: '',
+ },
+ }),
+ ),
+ on(
+ GorodarActions.areaFailed,
+ (state, { id, error }): GorodarState => ({
+ ...state,
+ areaDetailStatus: {
+ ...state.areaDetailStatus,
+ [id]: 'error',
+ },
+ areaDetailError: {
+ ...state.areaDetailError,
+ [id]: error,
+ },
+ }),
+ ),
+ on(
+ GorodarActions.attractionRequested,
+ (state, { id }): GorodarState => ({
+ ...state,
+ attractionStatus: {
+ ...state.attractionStatus,
+ [id]: 'loading',
+ },
+ attractionError: {
+ ...state.attractionError,
+ [id]: '',
+ },
+ }),
+ ),
+ on(
+ GorodarActions.attractionLoaded,
+ (state, { attraction }): GorodarState => ({
+ ...state,
+ attractions: {
+ ...state.attractions,
+ [attraction.id]: attraction,
+ },
+ attractionStatus: {
+ ...state.attractionStatus,
+ [attraction.id]: 'ready',
+ },
+ attractionError: {
+ ...state.attractionError,
+ [attraction.id]: '',
+ },
+ }),
+ ),
+ on(
+ GorodarActions.attractionFailed,
+ (state, { id, error }): GorodarState => ({
+ ...state,
+ attractionStatus: {
+ ...state.attractionStatus,
+ [id]: 'error',
+ },
+ attractionError: {
+ ...state.attractionError,
+ [id]: error,
+ },
}),
),
);
+function markVisited(item: Attraction, id: string): Attraction {
+ return item.id === id ? { ...item, visited: true } : item;
+}
+
+function markAreaVisited(
+ details: Record,
+ landmarkId: string,
+ progress: AreaProgress,
+): Record {
+ return Object.fromEntries(
+ Object.entries(details).map(([id, area]) => {
+ const contains = areaAttractions(area).some((item) => item.id === landmarkId);
+
+ if (!contains) {
+ return [id, area];
+ }
+
+ return [
+ id,
+ {
+ ...area,
+ progress: progress ?? area.progress,
+ attractions: area.attractions.map((item) => markVisited(item, landmarkId)),
+ children: area.children.map((child) => ({
+ ...child,
+ attractions: child.attractions.map((item) => markVisited(item, landmarkId)),
+ })),
+ },
+ ];
+ }),
+ );
+}
+
+function markAttractionVisited(
+ attractions: Record,
+ landmarkId: string,
+): Record {
+ const current = attractions[landmarkId];
+
+ if (!current) {
+ return attractions;
+ }
+
+ return {
+ ...attractions,
+ [landmarkId]: {
+ ...current,
+ visited: true,
+ },
+ };
+}
+
export const gorodarFeature = createFeature({
name: 'gorodar',
reducer: gorodarReducer,
diff --git a/src/app/state/gorodar.selectors.ts b/src/app/state/gorodar.selectors.ts
index 545814c..85d964d 100644
--- a/src/app/state/gorodar.selectors.ts
+++ b/src/app/state/gorodar.selectors.ts
@@ -1,6 +1,6 @@
import { createSelector } from '@ngrx/store';
-import { NIZHNY_NOVGOROD } from '../data/nizhny-novgorod';
+import { areaOpenedCount, areaTotalCount, type Area, type AreaDetails } from '../areas/area.models';
import { gorodarFeature } from './gorodar.reducer';
export const {
@@ -10,19 +10,37 @@ export const {
selectClaim,
selectProfile,
selectAuth,
+ selectAreas,
+ selectAreasStatus,
+ selectAreasError,
+ selectAreaDetails,
+ selectAreaDetailStatus,
+ selectAreaDetailError,
+ selectAttractions,
+ selectAttractionStatus,
+ selectAttractionError,
} = gorodarFeature;
export const selectCollectedIdSet = createSelector(selectCollectedIds, (ids) => new Set(ids));
-export const selectTotalCount = NIZHNY_NOVGOROD.objects.length;
-
export const selectOpenedCount = createSelector(
+ selectAreas,
+ selectAreaDetails,
selectCollectedIdSet,
- (ids) => NIZHNY_NOVGOROD.objects.filter((item) => ids.has(item.id) || item.collected).length,
+ (areas, details, ids) =>
+ areas.reduce((sum, area) => sum + areaOpenedCount(resolveArea(area, details), ids), 0),
);
-export const selectProgress = createSelector(selectOpenedCount, (opened) =>
- Math.round((opened / selectTotalCount) * 100),
+export const selectTotalCount = createSelector(selectAreas, selectAreaDetails, (areas, details) =>
+ areas.reduce((sum, area) => sum + areaTotalCount(resolveArea(area, details)), 0),
+);
+
+function resolveArea(area: Area, details: Record): Area | AreaDetails {
+ return details[area.id] ?? area;
+}
+
+export const selectProgress = createSelector(selectOpenedCount, selectTotalCount, (opened, total) =>
+ total ? Math.round((opened / total) * 100) : 0,
);
export const selectAuthenticated = createSelector(selectAuth, (auth) => auth.authenticated);
@@ -34,7 +52,3 @@ export const selectAuthResendSeconds = createSelector(selectAuth, (auth) => auth
export const selectAuthSheetVisible = createSelector(selectAuth, (auth) => auth.sheetVisible);
export const selectAuthIntent = createSelector(selectAuth, (auth) => auth.intent);
export const selectAuthCodeRequestId = createSelector(selectAuth, (auth) => auth.codeRequestId);
-
-export const selectClaimPhoto = createSelector(selectClaim, (claim) => claim.photo);
-export const selectClaimStage = createSelector(selectClaim, (claim) => claim.stage);
-export const selectClaimStep = createSelector(selectClaim, (claim) => claim.step);
diff --git a/src/app/state/index.ts b/src/app/state/index.ts
index 187843c..4f2ffca 100644
--- a/src/app/state/index.ts
+++ b/src/app/state/index.ts
@@ -1,4 +1,5 @@
export { GorodarActions } from './gorodar.actions';
+export { AreasEffects } from './areas.effects';
export { AuthEffects } from './auth.effects';
export { GorodarEffects } from './gorodar.effects';
export { gorodarFeature, initialState } from './gorodar.reducer';
diff --git a/src/environments/api.ts b/src/environments/api.ts
index 2ad881e..bde24d7 100644
--- a/src/environments/api.ts
+++ b/src/environments/api.ts
@@ -9,6 +9,10 @@ export const endpoints = {
authorize: `${API_URL}/oauth2/authorize`,
token: `${API_URL}/oauth2/token`,
},
+ areas: `${API_URL}/api/areas`,
+ area: (id: string) => `${API_URL}/api/areas/${id}`,
+ attraction: (id: string) => `${API_URL}/api/attractions/${id}`,
+ visit: (id: string) => `${API_URL}/api/attractions/${id}/visits`,
} as const;
export const grants = {
diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts
index ccc74ef..ead2195 100644
--- a/src/environments/environment.prod.ts
+++ b/src/environments/environment.prod.ts
@@ -1,4 +1,4 @@
export const environment = {
production: true,
- apiUrl: '',
+ apiUrl: 'https://gorodar.ru',
};
diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index cc5d6e9..4680181 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -1,4 +1,4 @@
export const environment = {
production: false,
- apiUrl: '',
+ apiUrl: 'https://gorodar.ru',
};
diff --git a/src/index.html b/src/index.html
index 47a292d..a215cfe 100644
--- a/src/index.html
+++ b/src/index.html
@@ -24,6 +24,5 @@
-