don't continue to play uri if user cancels purchase

This commit is contained in:
Sean Yesmunt 2020-05-22 15:09:32 -04:00
parent 047fb24731
commit 7eb759e0da
2 changed files with 16 additions and 7 deletions

View file

@ -1,20 +1,18 @@
import { connect } from 'react-redux'; 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 { doHideModal, doAnaltyicsPurchaseEvent } from 'redux/actions/app';
import { makeSelectMetadataForUri } from 'lbry-redux'; import { makeSelectMetadataForUri } from 'lbry-redux';
import ModalAffirmPurchase from './view'; import ModalAffirmPurchase from './view';
const select = (state, props) => ({ const select = (state, props) => ({
metadata: makeSelectMetadataForUri(props.uri)(state), metadata: makeSelectMetadataForUri(props.uri)(state),
playingUri: selectPlayingUri(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)), analyticsPurchaseEvent: fileInfo => dispatch(doAnaltyicsPurchaseEvent(fileInfo)),
cancelPurchase: () => { setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
// TODO: Find a way to add this back without messing up embeds
// dispatch(doSetPlayingUri(null));
dispatch(doHideModal());
},
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

@ -17,16 +17,19 @@ type Props = {
cancelPurchase: () => void, cancelPurchase: () => void,
metadata: StreamMetadata, metadata: StreamMetadata,
analyticsPurchaseEvent: GetResponse => void, analyticsPurchaseEvent: GetResponse => void,
playingUri: ?string,
setPlayingUri: (?string) => void,
}; };
function ModalAffirmPurchase(props: Props) { function ModalAffirmPurchase(props: Props) {
const { const {
cancelPurchase,
closeModal, closeModal,
loadVideo, loadVideo,
metadata: { title }, metadata: { title },
uri, uri,
analyticsPurchaseEvent, analyticsPurchaseEvent,
playingUri,
setPlayingUri,
} = 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 +45,14 @@ function ModalAffirmPurchase(props: Props) {
}); });
} }
function cancelPurchase() {
if (uri === playingUri) {
setPlayingUri(null);
}
closeModal();
}
React.useEffect(() => { React.useEffect(() => {
let timeout; let timeout;
if (success) { if (success) {