32 lines
1006 B
TypeScript
32 lines
1006 B
TypeScript
import { createSelector } from '@ngrx/store';
|
|
|
|
import { NIZHNY_NOVGOROD } from '../data/nizhny-novgorod';
|
|
import { gorodarFeature } from './gorodar.reducer';
|
|
|
|
export const {
|
|
selectCollectedIds,
|
|
selectPhotos,
|
|
selectCollectedAt,
|
|
selectClaim,
|
|
selectProfile,
|
|
} = gorodarFeature;
|
|
|
|
export const selectCollectedIdSet = createSelector(
|
|
selectCollectedIds,
|
|
(ids) => new Set(ids),
|
|
);
|
|
|
|
export const selectTotalCount = NIZHNY_NOVGOROD.objects.length;
|
|
|
|
export const selectOpenedCount = createSelector(selectCollectedIdSet, (ids) =>
|
|
NIZHNY_NOVGOROD.objects.filter((item) => ids.has(item.id) || item.collected).length,
|
|
);
|
|
|
|
export const selectProgress = createSelector(selectOpenedCount, (opened) =>
|
|
Math.round((opened / selectTotalCount) * 100),
|
|
);
|
|
|
|
export const selectClaimPhoto = createSelector(selectClaim, (claim) => claim.photo);
|
|
export const selectClaimStage = createSelector(selectClaim, (claim) => claim.stage);
|
|
export const selectClaimStep = createSelector(selectClaim, (claim) => claim.step);
|