From 7eb759e0da9fb5838aec922dcc264ac0e996e3ce Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 22 May 2020 15:09:32 -0400 Subject: [PATCH] don't continue to play uri if user cancels purchase --- ui/modal/modalAffirmPurchase/index.js | 10 ++++------ ui/modal/modalAffirmPurchase/view.jsx | 13 ++++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ui/modal/modalAffirmPurchase/index.js b/ui/modal/modalAffirmPurchase/index.js index 276c43a12..8730123ae 100644 --- a/ui/modal/modalAffirmPurchase/index.js +++ b/ui/modal/modalAffirmPurchase/index.js @@ -1,20 +1,18 @@ import { connect } from 'react-redux'; -import { doPlayUri } from 'redux/actions/content'; +import { doPlayUri, doSetPlayingUri } from 'redux/actions/content'; +import { selectPlayingUri } from 'redux/selectors/content'; import { doHideModal, doAnaltyicsPurchaseEvent } from 'redux/actions/app'; import { makeSelectMetadataForUri } from 'lbry-redux'; import ModalAffirmPurchase from './view'; const select = (state, props) => ({ metadata: makeSelectMetadataForUri(props.uri)(state), + playingUri: selectPlayingUri(state), }); const perform = dispatch => ({ analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)), - cancelPurchase: () => { - // TODO: Find a way to add this back without messing up embeds - // dispatch(doSetPlayingUri(null)); - dispatch(doHideModal()); - }, + setPlayingUri: uri => dispatch(doSetPlayingUri(uri)), closeModal: () => dispatch(doHideModal()), loadVideo: (uri, onSuccess) => dispatch(doPlayUri(uri, true, undefined, onSuccess)), }); diff --git a/ui/modal/modalAffirmPurchase/view.jsx b/ui/modal/modalAffirmPurchase/view.jsx index 2a346a9d2..000feb621 100644 --- a/ui/modal/modalAffirmPurchase/view.jsx +++ b/ui/modal/modalAffirmPurchase/view.jsx @@ -17,16 +17,19 @@ type Props = { cancelPurchase: () => void, metadata: StreamMetadata, analyticsPurchaseEvent: GetResponse => void, + playingUri: ?string, + setPlayingUri: (?string) => void, }; function ModalAffirmPurchase(props: Props) { const { - cancelPurchase, closeModal, loadVideo, metadata: { title }, uri, analyticsPurchaseEvent, + playingUri, + setPlayingUri, } = props; const [success, setSuccess] = React.useState(false); const [purchasing, setPurchasing] = React.useState(false); @@ -42,6 +45,14 @@ function ModalAffirmPurchase(props: Props) { }); } + function cancelPurchase() { + if (uri === playingUri) { + setPlayingUri(null); + } + + closeModal(); + } + React.useEffect(() => { let timeout; if (success) {