diff --git a/ui/component/invited/index.js b/ui/component/invited/index.js index 9237df1e2..84c04b498 100644 --- a/ui/component/invited/index.js +++ b/ui/component/invited/index.js @@ -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)), }); diff --git a/ui/component/invited/view.jsx b/ui/component/invited/view.jsx index 466dd5030..d64809f84 100644 --- a/ui/component/invited/view.jsx +++ b/ui/component/invited/view.jsx @@ -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, + 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}`); } diff --git a/ui/page/invited/index.js b/ui/page/invited/index.js index 4628a657d..1abc81952 100644 --- a/ui/page/invited/index.js +++ b/ui/page/invited/index.js @@ -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) +); diff --git a/ui/page/invited/view.jsx b/ui/page/invited/view.jsx index a136dcd93..8dd8f8e50 100644 --- a/ui/page/invited/view.jsx +++ b/ui/page/invited/view.jsx @@ -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 ( - + ); } diff --git a/yarn.lock b/yarn.lock index 7d8a1ff1b..389668882 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"