add logic
This commit is contained in:
@@ -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<string, AreaDetails>): 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);
|
||||
|
||||
Reference in New Issue
Block a user