lbry-desktop/ui/js/selectors/user.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-08 02:56:52 +02:00
import { createSelector } from "reselect";
2017-06-01 18:20:12 +02:00
2017-06-08 02:56:52 +02:00
export const _selectState = state => state.user || {};
2017-06-01 18:20:12 +02:00
export const selectAuthenticationIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.authenticationIsPending
);
2017-06-01 18:20:12 +02:00
export const selectUser = createSelector(
2017-06-01 18:20:12 +02:00
_selectState,
2017-06-08 02:56:52 +02:00
state => state.user || {}
);
2017-06-08 02:56:52 +02:00
export const selectEmailToVerify = createSelector(
2017-06-03 01:09:52 +02:00
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailToVerify
);
export const selectUserHasEmail = createSelector(
selectUser,
selectEmailToVerify,
(user, email) => user.has_email || email
);
export const selectUserIsRewardEligible = createSelector(
selectUser,
user => user.is_reward_eligible
);
export const selectUserIsRewardApproved = createSelector(
selectUser,
user => user.is_reward_approved
);
2017-06-03 01:09:52 +02:00
export const selectEmailNewIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewIsPending
);
export const selectEmailNewErrorMessage = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewErrorMessage
);
export const selectEmailNewDeclined = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewDeclined
);
2017-06-03 01:09:52 +02:00
export const selectEmailVerifyIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailVerifyIsPending
);
2017-06-03 01:09:52 +02:00
export const selectEmailVerifyErrorMessage = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailVerifyErrorMessage
);
export const selectUserIsVerificationCandidate = createSelector(
selectUserIsRewardEligible,
selectUserIsRewardApproved,
selectEmailToVerify,
selectUser,
(isEligible, isApproved, emailToVerify, user) =>
(isEligible && !isApproved) || (emailToVerify && !user.has_email)
);
export const selectUserIsAuthRequested = createSelector(
selectEmailNewDeclined,
selectAuthenticationIsPending,
selectUserIsVerificationCandidate,
selectUserHasEmail,
(isEmailDeclined, isPending, isVerificationCandidate, hasEmail) =>
!isEmailDeclined && (isPending || !hasEmail || isVerificationCandidate)
);