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 { 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)),
});

View file

@ -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) {