fix shortUrl subscriptions

refactor invited page
check if subscribed first
always follow regardless of reward status
This commit is contained in:
jessop 2020-01-10 19:13:04 -05:00 committed by Sean Yesmunt
parent d1c4e96d60
commit f130fae214
5 changed files with 56 additions and 41 deletions

View file

@ -2,27 +2,31 @@ import { connect } from 'react-redux';
import {
selectUser,
doClaimRewardType,
doUserFetch,
doUserSetReferrer,
selectSetReferrerPending,
selectSetReferrerError,
rewards as REWARDS,
selectUnclaimedRewards,
} from 'lbryinc';
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
import { doChannelSubscribe } from 'redux/actions/subscriptions';
import Invited from './view';
import { withRouter } from 'react-router';
const select = state => ({
user: selectUser(state),
referrerSetPending: selectSetReferrerPending(state),
referrerSetError: selectSetReferrerError(state),
rewards: selectUnclaimedRewards(state),
});
const select = (state, props) => {
return {
user: selectUser(state),
referrerSetPending: selectSetReferrerPending(state),
referrerSetError: selectSetReferrerError(state),
rewards: selectUnclaimedRewards(state),
isSubscribed: makeSelectIsSubscribed(props.fullUri)(state),
fullUri: props.fullUri,
referrer: props.referrer,
};
};
const perform = dispatch => ({
claimReward: () => dispatch(doClaimRewardType(REWARDS.TYPE_REFEREE)),
fetchUser: () => dispatch(doUserFetch()),
setReferrer: referrer => dispatch(doUserSetReferrer(referrer)),
channelSubscribe: uri => dispatch(doChannelSubscribe(uri)),
});

View file

@ -1,7 +1,6 @@
// @flow
import * as PAGES from 'constants/pages';
import React, { useEffect } from 'react';
import { useParams } from 'react-router';
import Button from 'component/button';
import ClaimPreview from 'component/claimPreview';
import Card from 'component/common/card';
@ -10,7 +9,6 @@ import { rewards as REWARDS, ERRORS } from 'lbryinc';
type Props = {
user: any,
fetchUser: () => void,
claimReward: () => void,
setReferrer: string => void,
referrerSetPending: boolean,
@ -18,12 +16,14 @@ type Props = {
channelSubscribe: (sub: Subscription) => void,
history: { push: string => void },
rewards: Array<Reward>,
referrer: string,
fullUri: string,
isSubscribed: boolean,
};
function Invited(props: Props) {
const {
user,
fetchUser,
claimReward,
setReferrer,
referrerSetPending,
@ -31,19 +31,26 @@ function Invited(props: Props) {
channelSubscribe,
history,
rewards,
fullUri,
referrer,
isSubscribed,
} = props;
// useParams requires react-router-dom ^v5.1.0
const { referrer } = useParams();
const refUri = 'lbry://' + referrer.replace(':', '#');
const refUri = referrer && 'lbry://' + referrer.replace(':', '#');
const referrerIsChannel = parseURI(refUri).isChannel;
const rewardsApproved = user && user.is_reward_approved;
const hasVerifiedEmail = user && user.has_verified_email;
const referredRewardAvailable = rewards && rewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE);
// always follow if it's a channel
useEffect(() => {
fetchUser();
}, []);
if (fullUri && !isSubscribed) {
channelSubscribe({
channelName: parseURI(fullUri).claimName,
uri: fullUri,
});
}
}, [fullUri, isSubscribed]);
useEffect(() => {
if (!referrerSetPending && hasVerifiedEmail) {
@ -57,23 +64,7 @@ function Invited(props: Props) {
}
}, [referrer]);
// if they land here due to a referrer but already claimed, make them follow anyway
useEffect(() => {
if (!referredRewardAvailable && referrerIsChannel) {
channelSubscribe({
channelName: parseURI(refUri).claimName,
uri: refUri,
});
}
}, [referredRewardAvailable, referrerIsChannel]);
function handleDone() {
if (hasVerifiedEmail && referrerIsChannel) {
channelSubscribe({
channelName: parseURI(refUri).claimName,
uri: refUri,
});
}
history.push(`/$/${PAGES.DISCOVER}`);
}

View file

@ -1,10 +1,24 @@
import { connect } from 'react-redux';
import InvitedPage from './view';
import { makeSelectPermanentUrlForUri } from 'lbry-redux';
import { withRouter } from 'react-router';
const select = () => ({});
const select = (state, props) => {
const { match } = props;
const { params } = match;
const { referrer } = params;
const sanitizedReferrer = referrer ? referrer.replace(':', '#') : '';
const uri = `lbry://${sanitizedReferrer}`;
return {
fullUri: makeSelectPermanentUrlForUri(uri)(state),
referrer: referrer,
};
};
const perform = () => ({});
export default connect(
select,
perform
)(InvitedPage);
export default withRouter(
connect(
select,
perform
)(InvitedPage)
);

View file

@ -3,10 +3,16 @@ import React from 'react';
import Page from 'component/page';
import Invited from 'component/invited';
export default function ReferredPage() {
type Props = {
fullUri: string,
referrer: string,
};
export default function ReferredPage(props: Props) {
const { fullUri, referrer } = props;
return (
<Page authPage className="main--auth-page">
<Invited />
<Invited fullUri={fullUri} referrer={referrer} />
</Page>
);
}

View file

@ -7071,9 +7071,9 @@ lbry-redux@lbryio/lbry-redux#a2be979986dc93be4c2c596846109f5394f64fa1:
reselect "^3.0.0"
uuid "^3.3.2"
lbryinc@lbryio/lbryinc#6042c6f7bbf5fe7c6db2bd169f5b1c4558485c4c:
lbryinc@lbryio/lbryinc#018d149fb493615c7179d1ea3c497f07b9c8aed6:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/6042c6f7bbf5fe7c6db2bd169f5b1c4558485c4c"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/018d149fb493615c7179d1ea3c497f07b9c8aed6"
dependencies:
reselect "^3.0.0"