diff --git a/package.json b/package.json index 2fb8e176c..445815720 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "imagesloaded": "^4.1.4", "json-loader": "^0.5.4", "lbry-format": "https://github.com/lbryio/lbry-format.git", - "lbry-redux": "lbryio/lbry-redux#3d64f8acc6c2ce37252f59feff89e1fc58cb74c1", + "lbry-redux": "lbryio/lbry-redux#adebb2d6259e9f69ca055a8a8c0c01fac0af6124", "lbryinc": "lbryio/lbryinc#6a59102c52673502569d2c43bd4ee58c315fb2e4", "lint-staged": "^7.0.2", "localforage": "^1.7.1", diff --git a/static/app-strings.json b/static/app-strings.json index 82fcc440c..54312c1a4 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -956,4 +956,4 @@ "Thumbnail Recommended ratio is 1:1": "Thumbnail Recommended ratio is 1:1", "Cover Recommended ratio is 6.25:1": "Cover Recommended ratio is 6.25:1", "You already have a claim with this name.": "You already have a claim with this name." -} \ No newline at end of file +} diff --git a/ui/component/inviteNew/index.js b/ui/component/inviteNew/index.js index fdd549d70..065a298f4 100644 --- a/ui/component/inviteNew/index.js +++ b/ui/component/inviteNew/index.js @@ -7,7 +7,13 @@ import { selectUserInviteReferralCode, doUserInviteNew, } from 'lbryinc'; -import { selectMyChannelClaims, selectFetchingMyChannels, doFetchChannelListMine } from 'lbry-redux'; +import { + selectMyChannelClaims, + selectFetchingMyChannels, + doFetchChannelListMine, + doResolveUris, + selectResolvingUris, +} from 'lbry-redux'; import InviteNew from './view'; const select = state => ({ @@ -18,11 +24,13 @@ const select = state => ({ isPending: selectUserInviteNewIsPending(state), channels: selectMyChannelClaims(state), fetchingChannels: selectFetchingMyChannels(state), + resolvingUris: selectResolvingUris(state), }); const perform = dispatch => ({ inviteNew: email => dispatch(doUserInviteNew(email)), fetchChannelListMine: () => dispatch(doFetchChannelListMine()), + resolveUris: uris => dispatch(doResolveUris(uris)), }); export default connect( diff --git a/ui/component/inviteNew/view.jsx b/ui/component/inviteNew/view.jsx index 4dc1e0c67..f6b2a7d3e 100644 --- a/ui/component/inviteNew/view.jsx +++ b/ui/component/inviteNew/view.jsx @@ -16,10 +16,12 @@ type Props = { referralLink: string, referralCode: string, channels: ?Array, + resolvingUris: Array, + resolveUris: (Array) => void, }; function InviteNew(props: Props) { - const { inviteNew, errorMessage, isPending, referralCode = '', channels } = props; + const { inviteNew, errorMessage, isPending, referralCode = '', channels, resolveUris, resolvingUris } = props; const rewardAmount = 20; // Email @@ -34,6 +36,9 @@ function InviteNew(props: Props) { // Referral link const [referralSource, setReferralSource] = useState(referralCode); + /* Canonical Referral links + * We need to make sure our channels are resolved so that canonical_url is present + */ function handleReferralChange(code) { setReferralSource(code); @@ -44,6 +49,13 @@ function InviteNew(props: Props) { } } + const [resolveStarted, setResolveStarted] = useState(false); + const [hasResolved, setHasResolved] = useState(false); + // join them so that useEffect doesn't update on new objects + const uris = channels && channels.map(channel => channel.permanent_url).join(','); + const channelCount = channels && channels.length; + const resolvingCount = resolvingUris && resolvingUris.length; + const topChannel = channels && channels.reduce((top, channel) => { @@ -58,12 +70,27 @@ function InviteNew(props: Props) { const referral = `${URL}/$/invite/${referralString.replace('#', ':')}`; + useEffect(() => { + // resolve once, after we have channel list + if (!hasResolved && !resolveStarted && channelCount && uris) { + setResolveStarted(true); + resolveUris(uris.split(',')); + } + }, [channelCount, resolveStarted, hasResolved, resolvingCount, uris]); + + useEffect(() => { + // once resolving count is 0, we know we're done + if (resolveStarted && !hasResolved && resolvingCount === 0) { + setHasResolved(true); + } + }, [resolveStarted, hasResolved, resolvingCount]); + useEffect(() => { // set default channel - if (topChannel) { + if (topChannel && hasResolved) { handleReferralChange(topChannel.name); } - }, [topChannel]); + }, [topChannel, hasResolved]); function lookupUrlByClaimName(name, channels) { const claim = channels.find(channel => channel.name === name); diff --git a/yarn.lock b/yarn.lock index d83c2d4d6..6b5a0f43a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7174,9 +7174,9 @@ lazy-val@^1.0.4: yargs "^13.2.2" zstd-codec "^0.1.1" -lbry-redux@lbryio/lbry-redux#3d64f8acc6c2ce37252f59feff89e1fc58cb74c1: +lbry-redux@lbryio/lbry-redux#adebb2d6259e9f69ca055a8a8c0c01fac0af6124: version "0.0.1" - resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/3d64f8acc6c2ce37252f59feff89e1fc58cb74c1" + resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/adebb2d6259e9f69ca055a8a8c0c01fac0af6124" dependencies: proxy-polyfill "0.1.6" reselect "^3.0.0"