50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { createSelector } from '@ngrx/store';
|
|
|
|
import { areaOpenedCount, areaTotalCount, type Area, type AreaDetails } from '../areas/area.models';
|
|
import { gorodarFeature } from './gorodar.reducer';
|
|
|
|
export const {
|
|
selectPhotos,
|
|
selectCollectedAt,
|
|
selectClaim,
|
|
selectProfile,
|
|
selectAuth,
|
|
selectAreas,
|
|
selectAreasStatus,
|
|
selectAreasError,
|
|
selectAreaDetails,
|
|
selectAreaDetailStatus,
|
|
selectAreaDetailError,
|
|
selectAttractions,
|
|
selectAttractionStatus,
|
|
selectAttractionError,
|
|
} = gorodarFeature;
|
|
|
|
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) =>
|
|
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);
|
|
export const selectAuthEmail = createSelector(selectAuth, (auth) => auth.email);
|
|
export const selectAuthStep = createSelector(selectAuth, (auth) => auth.step);
|
|
export const selectAuthError = createSelector(selectAuth, (auth) => auth.error);
|
|
export const selectAuthPending = createSelector(selectAuth, (auth) => auth.pending);
|
|
export const selectAuthResendSeconds = createSelector(selectAuth, (auth) => auth.resendSeconds);
|
|
export const selectAuthSheetVisible = createSelector(selectAuth, (auth) => auth.sheetVisible);
|
|
export const selectAuthIntent = createSelector(selectAuth, (auth) => auth.intent);
|
|
export const selectAuthCodeRequestId = createSelector(selectAuth, (auth) => auth.codeRequestId);
|