don't set setting until preferences are ready
This commit is contained in:
parent
02792b8f0c
commit
c29dccc1b1
2 changed files with 10 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
import REWARD_TYPES from 'rewards';
|
import REWARD_TYPES from 'rewards';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { selectGetSyncIsPending, selectSyncHash } from 'redux/selectors/sync';
|
import { selectGetSyncIsPending, selectSyncHash, selectPrefsReady } from 'redux/selectors/sync';
|
||||||
import { doClaimRewardType } from 'redux/actions/rewards';
|
import { doClaimRewardType } from 'redux/actions/rewards';
|
||||||
import { doSetClientSetting } from 'redux/actions/settings';
|
import { doSetClientSetting } from 'redux/actions/settings';
|
||||||
import { selectClaimedRewards, makeSelectIsRewardClaimPending } from 'redux/selectors/rewards';
|
import { selectClaimedRewards, makeSelectIsRewardClaimPending } from 'redux/selectors/rewards';
|
||||||
|
@ -22,11 +22,9 @@ import {
|
||||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||||
import { selectInterestedInYoutubeSync } from 'redux/selectors/app';
|
import { selectInterestedInYoutubeSync } from 'redux/selectors/app';
|
||||||
import { doToggleInterestedInYoutubeSync } from 'redux/actions/app';
|
import { doToggleInterestedInYoutubeSync } from 'redux/actions/app';
|
||||||
import { doSetPrefsReady } from 'redux/actions/sync';
|
|
||||||
|
|
||||||
import UserSignIn from './view';
|
import UserSignIn from './view';
|
||||||
|
|
||||||
const select = state => ({
|
const select = (state) => ({
|
||||||
emailToVerify: selectEmailToVerify(state),
|
emailToVerify: selectEmailToVerify(state),
|
||||||
user: selectUser(state),
|
user: selectUser(state),
|
||||||
accessToken: selectAccessToken(state),
|
accessToken: selectAccessToken(state),
|
||||||
|
@ -47,9 +45,10 @@ const select = state => ({
|
||||||
hasSynced: Boolean(selectSyncHash(state)),
|
hasSynced: Boolean(selectSyncHash(state)),
|
||||||
creatingChannel: selectCreatingChannel(state),
|
creatingChannel: selectCreatingChannel(state),
|
||||||
interestedInYoutubeSync: selectInterestedInYoutubeSync(state),
|
interestedInYoutubeSync: selectInterestedInYoutubeSync(state),
|
||||||
|
prefsReady: selectPrefsReady(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = (dispatch) => ({
|
||||||
fetchUser: () => dispatch(doUserFetch()),
|
fetchUser: () => dispatch(doUserFetch()),
|
||||||
claimConfirmEmailReward: () =>
|
claimConfirmEmailReward: () =>
|
||||||
dispatch(
|
dispatch(
|
||||||
|
@ -65,7 +64,6 @@ const perform = dispatch => ({
|
||||||
),
|
),
|
||||||
setClientSetting: (setting, value, pushToPrefs) => dispatch(doSetClientSetting(setting, value, pushToPrefs)),
|
setClientSetting: (setting, value, pushToPrefs) => dispatch(doSetClientSetting(setting, value, pushToPrefs)),
|
||||||
doToggleInterestedInYoutubeSync: () => dispatch(doToggleInterestedInYoutubeSync()),
|
doToggleInterestedInYoutubeSync: () => dispatch(doToggleInterestedInYoutubeSync()),
|
||||||
setPrefsReady: () => dispatch(doSetPrefsReady()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(UserSignIn);
|
export default connect(select, perform)(UserSignIn);
|
||||||
|
|
|
@ -46,7 +46,7 @@ type Props = {
|
||||||
rewardsAcknowledged: boolean,
|
rewardsAcknowledged: boolean,
|
||||||
interestedInYoutubeSync: boolean,
|
interestedInYoutubeSync: boolean,
|
||||||
doToggleInterestedInYoutubeSync: () => void,
|
doToggleInterestedInYoutubeSync: () => void,
|
||||||
setPrefsReady: () => void,
|
prefsReady: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function UserSignUp(props: Props) {
|
function UserSignUp(props: Props) {
|
||||||
|
@ -72,7 +72,7 @@ function UserSignUp(props: Props) {
|
||||||
setClientSetting,
|
setClientSetting,
|
||||||
interestedInYoutubeSync,
|
interestedInYoutubeSync,
|
||||||
doToggleInterestedInYoutubeSync,
|
doToggleInterestedInYoutubeSync,
|
||||||
setPrefsReady,
|
prefsReady,
|
||||||
} = props;
|
} = props;
|
||||||
const {
|
const {
|
||||||
location: { search, pathname },
|
location: { search, pathname },
|
||||||
|
@ -90,12 +90,12 @@ function UserSignUp(props: Props) {
|
||||||
const hasFetchedReward = useFetched(claimingReward);
|
const hasFetchedReward = useFetched(claimingReward);
|
||||||
const previousHasVerifiedEmail = usePrevious(hasVerifiedEmail);
|
const previousHasVerifiedEmail = usePrevious(hasVerifiedEmail);
|
||||||
const channelCount = channels ? channels.length : 0;
|
const channelCount = channels ? channels.length : 0;
|
||||||
const hasClaimedEmailAward = claimedRewards.some(reward => reward.reward_type === REWARDS.TYPE_CONFIRM_EMAIL);
|
const hasClaimedEmailAward = claimedRewards.some((reward) => reward.reward_type === REWARDS.TYPE_CONFIRM_EMAIL);
|
||||||
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
|
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
|
||||||
const isYoutubeTransferComplete =
|
const isYoutubeTransferComplete =
|
||||||
hasYoutubeChannels &&
|
hasYoutubeChannels &&
|
||||||
youtubeChannels.every(
|
youtubeChannels.every(
|
||||||
channel =>
|
(channel) =>
|
||||||
channel.transfer_state === YOUTUBE_STATUSES.COMPLETED_TRANSFER ||
|
channel.transfer_state === YOUTUBE_STATUSES.COMPLETED_TRANSFER ||
|
||||||
channel.sync_status === YOUTUBE_STATUSES.YOUTUBE_SYNC_ABANDONDED
|
channel.sync_status === YOUTUBE_STATUSES.YOUTUBE_SYNC_ABANDONDED
|
||||||
);
|
);
|
||||||
|
@ -136,11 +136,10 @@ function UserSignUp(props: Props) {
|
||||||
}, [fetchUser]);
|
}, [fetchUser]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (previousHasVerifiedEmail === false && hasVerifiedEmail) {
|
if (previousHasVerifiedEmail === false && hasVerifiedEmail && prefsReady) {
|
||||||
setPrefsReady();
|
|
||||||
setSettingAndSync(SETTINGS.FIRST_RUN_STARTED, true);
|
setSettingAndSync(SETTINGS.FIRST_RUN_STARTED, true);
|
||||||
}
|
}
|
||||||
}, [hasVerifiedEmail, previousHasVerifiedEmail, setPrefsReady]);
|
}, [hasVerifiedEmail, previousHasVerifiedEmail, prefsReady]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Don't claim the reward if sync is enabled until after a sync has been completed successfully
|
// Don't claim the reward if sync is enabled until after a sync has been completed successfully
|
||||||
|
|
Loading…
Reference in a new issue