fix and add documents view
This commit is contained in:
@@ -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<string, AreaDetails>,
|
||||
landmarkId: string,
|
||||
|
||||
Reference in New Issue
Block a user