From 4c768b38145d6cf03f7459958e2395640722a76b Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 21 May 2020 12:53:21 -0400 Subject: [PATCH] fix embed player --- ui/component/embedPlayButton/index.js | 2 ++ ui/component/embedPlayButton/view.jsx | 23 +++++++++++++++-------- ui/modal/modalAffirmPurchase/index.js | 5 +++-- ui/redux/reducers/content.js | 13 ++++++------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ui/component/embedPlayButton/index.js b/ui/component/embedPlayButton/index.js index bd9bcab9f..1a350a971 100644 --- a/ui/component/embedPlayButton/index.js +++ b/ui/component/embedPlayButton/index.js @@ -3,6 +3,7 @@ import { connect } from 'react-redux'; import { makeSelectThumbnailForUri, doResolveUri, makeSelectClaimForUri } from 'lbry-redux'; import { doFetchCostInfoForUri } from 'lbryinc'; import { doSetFloatingUri, doPlayUri } from 'redux/actions/content'; +import { doAnaltyicsPurchaseEvent } from 'redux/actions/app'; import { makeSelectClientSetting } from 'redux/selectors/settings'; import ChannelThumbnail from './view'; @@ -17,4 +18,5 @@ export default connect(select, { doFetchCostInfoForUri, doSetFloatingUri, doPlayUri, + doAnaltyicsPurchaseEvent, })(ChannelThumbnail); diff --git a/ui/component/embedPlayButton/view.jsx b/ui/component/embedPlayButton/view.jsx index 5a0ec6f6b..1fcbef1d9 100644 --- a/ui/component/embedPlayButton/view.jsx +++ b/ui/component/embedPlayButton/view.jsx @@ -14,7 +14,8 @@ type Props = { doFetchCostInfoForUri: string => void, doSetFloatingUri: string => void, floatingPlayerEnabled: boolean, - doPlayUri: string => void, + doPlayUri: (string, ?boolean, ?boolean, (GetResponse) => void) => void, + doAnaltyicsPurchaseEvent: GetResponse => void, }; export default function FileRenderFloating(props: Props) { @@ -27,30 +28,36 @@ export default function FileRenderFloating(props: Props) { doSetFloatingUri, floatingPlayerEnabled, doPlayUri, + doAnaltyicsPurchaseEvent, } = props; const { push } = useHistory(); const isMobile = useIsMobile(); const hasResolvedUri = claim !== undefined; useEffect(() => { - if (!hasResolvedUri) { - doResolveUri(uri); - doFetchCostInfoForUri(uri); - } - }, [uri, hasResolvedUri, doResolveUri, doFetchCostInfoForUri]); + doResolveUri(uri); + doFetchCostInfoForUri(uri); + }, [uri, doResolveUri, doFetchCostInfoForUri]); function handleClick() { + if (!hasResolvedUri) { + return; + } + if (isMobile || !floatingPlayerEnabled) { const formattedUrl = formatLbryUrlForWeb(uri); push(formattedUrl); } else { - doSetFloatingUri(uri); - doPlayUri(uri); + doPlayUri(uri, undefined, undefined, fileInfo => { + doSetFloatingUri(uri); + doAnaltyicsPurchaseEvent(fileInfo); + }); } } return (
({ const perform = dispatch => ({ analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)), cancelPurchase: () => { - dispatch(doSetPlayingUri(null)); + // TODO: Find a way to add this back without messing up embeds + // dispatch(doSetPlayingUri(null)); dispatch(doHideModal()); }, closeModal: () => dispatch(doHideModal()), diff --git a/ui/redux/reducers/content.js b/ui/redux/reducers/content.js index eb9a1473a..cd5f9eb99 100644 --- a/ui/redux/reducers/content.js +++ b/ui/redux/reducers/content.js @@ -1,5 +1,4 @@ import * as ACTIONS from 'constants/action_types'; -import { ACTIONS as LBRY_REDUX_ACTIONS } from 'lbry-redux'; const reducers = {}; const defaultState = { @@ -90,12 +89,12 @@ reducers[ACTIONS.CLEAR_CONTENT_HISTORY_URI] = (state, action) => { reducers[ACTIONS.CLEAR_CONTENT_HISTORY_ALL] = state => ({ ...state, history: [] }); -reducers[LBRY_REDUX_ACTIONS.PURCHASE_URI_FAILED] = (state, action) => { - return { - ...state, - playingUri: null, - }; -}; +// reducers[LBRY_REDUX_ACTIONS.PURCHASE_URI_FAILED] = (state, action) => { +// return { +// ...state, +// playingUri: null, +// }; +// }; export default function reducer(state = defaultState, action) { const handler = reducers[action.type];