improve first time play experience for paid content in blog posts

This commit is contained in:
Sean Yesmunt 2020-05-25 13:20:45 -04:00
parent b244261715
commit 8b68932997
4 changed files with 16 additions and 5 deletions

View file

@ -1,7 +1,7 @@
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectThumbnailForUri, doResolveUri, makeSelectClaimForUri } from 'lbry-redux'; import { makeSelectThumbnailForUri, doResolveUri, makeSelectClaimForUri } from 'lbry-redux';
import { doFetchCostInfoForUri } from 'lbryinc'; import { doFetchCostInfoForUri, makeSelectCostInfoForUri } from 'lbryinc';
import { doSetFloatingUri, doPlayUri } from 'redux/actions/content'; import { doSetFloatingUri, doPlayUri } from 'redux/actions/content';
import { doAnaltyicsPurchaseEvent } from 'redux/actions/app'; import { doAnaltyicsPurchaseEvent } from 'redux/actions/app';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings';
@ -11,6 +11,7 @@ const select = (state, props) => ({
thumbnail: makeSelectThumbnailForUri(props.uri)(state), thumbnail: makeSelectThumbnailForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state), floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state),
}); });
export default connect(select, { export default connect(select, {

View file

@ -13,12 +13,13 @@ type Props = {
doResolveUri: string => void, doResolveUri: string => void,
doFetchCostInfoForUri: string => void, doFetchCostInfoForUri: string => void,
doSetFloatingUri: string => void, doSetFloatingUri: string => void,
costInfo: ?{ cost: number },
floatingPlayerEnabled: boolean, floatingPlayerEnabled: boolean,
doPlayUri: (string, ?boolean, ?boolean, (GetResponse) => void) => void, doPlayUri: (string, ?boolean, ?boolean, (GetResponse) => void) => void,
doAnaltyicsPurchaseEvent: GetResponse => void, doAnaltyicsPurchaseEvent: GetResponse => void,
}; };
export default function FileRenderFloating(props: Props) { export default function EmbedPlayButton(props: Props) {
const { const {
uri, uri,
thumbnail = '', thumbnail = '',
@ -29,10 +30,12 @@ export default function FileRenderFloating(props: Props) {
floatingPlayerEnabled, floatingPlayerEnabled,
doPlayUri, doPlayUri,
doAnaltyicsPurchaseEvent, doAnaltyicsPurchaseEvent,
costInfo,
} = props; } = props;
const { push } = useHistory(); const { push } = useHistory();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const hasResolvedUri = claim !== undefined; const hasResolvedUri = claim !== undefined;
const disabled = !hasResolvedUri || !costInfo;
useEffect(() => { useEffect(() => {
doResolveUri(uri); doResolveUri(uri);
@ -40,7 +43,7 @@ export default function FileRenderFloating(props: Props) {
}, [uri, doResolveUri, doFetchCostInfoForUri]); }, [uri, doResolveUri, doFetchCostInfoForUri]);
function handleClick() { function handleClick() {
if (!hasResolvedUri) { if (disabled) {
return; return;
} }
@ -57,7 +60,7 @@ export default function FileRenderFloating(props: Props) {
return ( return (
<div <div
disabled={!hasResolvedUri} disabled={disabled}
role="button" role="button"
className="embed__inline-button" className="embed__inline-button"
onClick={handleClick} onClick={handleClick}

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content'; import { doPlayUri, doSetPlayingUri, doSetFloatingUri } from 'redux/actions/content';
import { selectPlayingUri } from 'redux/selectors/content'; import { selectPlayingUri } from 'redux/selectors/content';
import { doHideModal, doAnaltyicsPurchaseEvent } from 'redux/actions/app'; import { doHideModal, doAnaltyicsPurchaseEvent } from 'redux/actions/app';
import { makeSelectMetadataForUri } from 'lbry-redux'; import { makeSelectMetadataForUri } from 'lbry-redux';
@ -13,6 +13,7 @@ const select = (state, props) => ({
const perform = dispatch => ({ const perform = dispatch => ({
analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)), analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)),
setPlayingUri: uri => dispatch(doSetPlayingUri(uri)), setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
setFloatingUri: uri => dispatch(doSetFloatingUri(uri)),
closeModal: () => dispatch(doHideModal()), closeModal: () => dispatch(doHideModal()),
loadVideo: (uri, onSuccess) => dispatch(doPlayUri(uri, true, undefined, onSuccess)), loadVideo: (uri, onSuccess) => dispatch(doPlayUri(uri, true, undefined, onSuccess)),
}); });

View file

@ -19,6 +19,7 @@ type Props = {
analyticsPurchaseEvent: GetResponse => void, analyticsPurchaseEvent: GetResponse => void,
playingUri: ?string, playingUri: ?string,
setPlayingUri: (?string) => void, setPlayingUri: (?string) => void,
setFloatingUri: (?string) => void,
}; };
function ModalAffirmPurchase(props: Props) { function ModalAffirmPurchase(props: Props) {
@ -30,6 +31,7 @@ function ModalAffirmPurchase(props: Props) {
analyticsPurchaseEvent, analyticsPurchaseEvent,
playingUri, playingUri,
setPlayingUri, setPlayingUri,
setFloatingUri,
} = props; } = props;
const [success, setSuccess] = React.useState(false); const [success, setSuccess] = React.useState(false);
const [purchasing, setPurchasing] = React.useState(false); const [purchasing, setPurchasing] = React.useState(false);
@ -42,6 +44,10 @@ function ModalAffirmPurchase(props: Props) {
setPurchasing(false); setPurchasing(false);
setSuccess(true); setSuccess(true);
analyticsPurchaseEvent(fileInfo); analyticsPurchaseEvent(fileInfo);
if (playingUri !== uri) {
setFloatingUri(uri);
}
}); });
} }