fix pending play issue introduced much earlier in branch
This commit is contained in:
parent
b5dc588e23
commit
e741d5ee27
12 changed files with 67 additions and 79 deletions
|
@ -322,38 +322,29 @@ export function doPurchaseUri(uri) {
|
||||||
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
||||||
const alreadyDownloading =
|
const alreadyDownloading =
|
||||||
fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
||||||
|
|
||||||
// we already fully downloaded the file.
|
|
||||||
if (fileInfo && fileInfo.completed) {
|
|
||||||
// If written_bytes is false that means the user has deleted/moved the
|
|
||||||
// file manually on their file system, so we need to dispatch a
|
|
||||||
// doLoadVideo action to reconstruct the file from the blobs
|
|
||||||
if (!fileInfo.written_bytes) dispatch(doLoadVideo(uri));
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we are already downloading the file
|
|
||||||
if (alreadyDownloading) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
||||||
const { cost } = costInfo;
|
const { cost } = costInfo;
|
||||||
|
|
||||||
// the file is free or we have partially downloaded it
|
if (
|
||||||
if (cost === 0 || (fileInfo && fileInfo.download_directory)) {
|
alreadyDownloading ||
|
||||||
dispatch(doLoadVideo(uri));
|
(fileInfo && fileInfo.completed && fileInfo.written_bytes > 0)
|
||||||
return Promise.resolve();
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we already fully downloaded the file.
|
||||||
|
if (
|
||||||
|
cost === 0 ||
|
||||||
|
(fileInfo && (fileInfo.completed || fileInfo.download_directory))
|
||||||
|
) {
|
||||||
|
return dispatch(doLoadVideo(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cost > balance) {
|
if (cost > balance) {
|
||||||
dispatch(doOpenModal(modals.INSUFFICIENT_CREDITS));
|
return dispatch(doOpenModal(modals.INSUFFICIENT_CREDITS));
|
||||||
} else {
|
|
||||||
dispatch(doOpenModal(modals.AFFIRM_PURCHASE, { uri }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve();
|
return dispatch(doOpenModal(modals.AFFIRM_PURCHASE, { uri }));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,6 +411,22 @@ export function doFetchClaimListMine() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doPlayUri(uri) {
|
||||||
|
return function(dispatch, getState) {
|
||||||
|
dispatch(doSetPlayingUri(uri));
|
||||||
|
dispatch(doPurchaseUri(uri));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doSetPlayingUri(uri) {
|
||||||
|
return function(dispatch, getState) {
|
||||||
|
dispatch({
|
||||||
|
type: types.SET_PLAYING_URI,
|
||||||
|
data: { uri },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function doFetchChannelListMine() {
|
export function doFetchChannelListMine() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -3,11 +3,7 @@ import { connect } from "react-redux";
|
||||||
import { makeSelectFileInfoForUri } from "selectors/file_info";
|
import { makeSelectFileInfoForUri } from "selectors/file_info";
|
||||||
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
||||||
import { doOpenModal } from "actions/app";
|
import { doOpenModal } from "actions/app";
|
||||||
import { doFetchAvailability } from "actions/availability";
|
|
||||||
import { doOpenFileInShell } from "actions/file_info";
|
|
||||||
import { makeSelectClaimIsMine } from "selectors/claims";
|
import { makeSelectClaimIsMine } from "selectors/claims";
|
||||||
import { doPurchaseUri, doStartDownload } from "actions/content";
|
|
||||||
import { doNavigate } from "actions/navigation";
|
|
||||||
import FileActions from "./view";
|
import FileActions from "./view";
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
|
@ -18,12 +14,7 @@ const select = (state, props) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
checkAvailability: uri => dispatch(doFetchAvailability(uri)),
|
|
||||||
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
|
||||||
openInShell: fileInfo => dispatch(doOpenFileInShell(fileInfo)),
|
|
||||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||||
startDownload: uri => dispatch(doPurchaseUri(uri)),
|
|
||||||
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(FileActions);
|
export default connect(select, perform)(FileActions);
|
||||||
|
|
|
@ -23,8 +23,7 @@ const select = (state, props) => ({
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
checkAvailability: uri => dispatch(doFetchAvailability(uri)),
|
checkAvailability: uri => dispatch(doFetchAvailability(uri)),
|
||||||
openInShell: fileInfo => dispatch(doOpenFileInShell(fileInfo)),
|
openInShell: fileInfo => dispatch(doOpenFileInShell(fileInfo)),
|
||||||
startDownload: uri =>
|
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
||||||
dispatch(doPurchaseUri(uri, modals.CONFIRM_FILE_PURCHASE)),
|
|
||||||
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class FileDownloadLink extends React.PureComponent {
|
||||||
downloading,
|
downloading,
|
||||||
uri,
|
uri,
|
||||||
openInShell,
|
openInShell,
|
||||||
startDownload,
|
purchaseUri,
|
||||||
costInfo,
|
costInfo,
|
||||||
loading,
|
loading,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
@ -81,7 +81,7 @@ class FileDownloadLink extends React.PureComponent {
|
||||||
label={__("Download")}
|
label={__("Download")}
|
||||||
icon="icon-download"
|
icon="icon-download"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
startDownload(uri);
|
purchaseUri(uri);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { doCloseModal } from "actions/app";
|
|
||||||
import { doChangeVolume } from "actions/app";
|
import { doChangeVolume } from "actions/app";
|
||||||
import { selectCurrentModal, selectVolume } from "selectors/app";
|
import { selectVolume } from "selectors/app";
|
||||||
import { doPurchaseUri, doLoadVideo } from "actions/content";
|
import { doPlayUri } from "actions/content";
|
||||||
import {
|
import {
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
makeSelectContentTypeForUri,
|
makeSelectContentTypeForUri,
|
||||||
|
@ -16,6 +15,7 @@ import {
|
||||||
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
import { makeSelectCostInfoForUri } from "selectors/cost_info";
|
||||||
import { selectShowNsfw } from "selectors/settings";
|
import { selectShowNsfw } from "selectors/settings";
|
||||||
import Video from "./view";
|
import Video from "./view";
|
||||||
|
import { selectPlayingUri } from "selectors/content";
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||||
|
@ -24,13 +24,13 @@ const select = (state, props) => ({
|
||||||
obscureNsfw: !selectShowNsfw(state),
|
obscureNsfw: !selectShowNsfw(state),
|
||||||
isLoading: makeSelectLoadingForUri(props.uri)(state),
|
isLoading: makeSelectLoadingForUri(props.uri)(state),
|
||||||
isDownloading: makeSelectDownloadingForUri(props.uri)(state),
|
isDownloading: makeSelectDownloadingForUri(props.uri)(state),
|
||||||
|
playingUri: selectPlayingUri(state),
|
||||||
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
||||||
volume: selectVolume(state),
|
volume: selectVolume(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
loadVideo: uri => dispatch(doLoadVideo(uri)),
|
play: uri => dispatch(doPlayUri(uri)),
|
||||||
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
|
||||||
changeVolume: volume => dispatch(doChangeVolume(volume)),
|
changeVolume: volume => dispatch(doChangeVolume(volume)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,12 @@ class VideoPlayButton extends React.PureComponent {
|
||||||
"Space" === event.code
|
"Space" === event.code
|
||||||
) {
|
) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.onWatchClick();
|
this.watch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onWatchClick() {
|
watch() {
|
||||||
this.props.purchaseUri(this.props.uri).then(() => {
|
this.props.play(this.props.uri);
|
||||||
if (!this.props.modal) {
|
|
||||||
this.props.startPlaying();
|
|
||||||
} else {
|
|
||||||
alert("fix me set pending play");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -54,7 +48,7 @@ class VideoPlayButton extends React.PureComponent {
|
||||||
label={label ? label : ""}
|
label={label ? label : ""}
|
||||||
className="video__play-button"
|
className="video__play-button"
|
||||||
icon={icon}
|
icon={icon}
|
||||||
onClick={this.onWatchClick.bind(this)}
|
onClick={() => this.watch()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,22 +9,10 @@ class Video extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
isPlaying: false,
|
|
||||||
showNsfwHelp: false,
|
showNsfwHelp: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
// reset playing state upon change path action
|
|
||||||
if (
|
|
||||||
!this.isMediaSame(nextProps) &&
|
|
||||||
this.props.fileInfo &&
|
|
||||||
this.state.isPlaying
|
|
||||||
) {
|
|
||||||
this.state.isPlaying = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isMediaSame(nextProps) {
|
isMediaSame(nextProps) {
|
||||||
return (
|
return (
|
||||||
this.props.fileInfo &&
|
this.props.fileInfo &&
|
||||||
|
@ -33,12 +21,6 @@ class Video extends React.PureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
startPlaying() {
|
|
||||||
this.setState({
|
|
||||||
isPlaying: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleMouseOver() {
|
handleMouseOver() {
|
||||||
if (
|
if (
|
||||||
this.props.obscureNsfw &&
|
this.props.obscureNsfw &&
|
||||||
|
@ -64,13 +46,15 @@ class Video extends React.PureComponent {
|
||||||
metadata,
|
metadata,
|
||||||
isLoading,
|
isLoading,
|
||||||
isDownloading,
|
isDownloading,
|
||||||
|
playingUri,
|
||||||
fileInfo,
|
fileInfo,
|
||||||
contentType,
|
contentType,
|
||||||
changeVolume,
|
changeVolume,
|
||||||
volume,
|
volume,
|
||||||
|
uri,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { isPlaying = false } = this.state;
|
|
||||||
|
|
||||||
|
const isPlaying = playingUri === uri;
|
||||||
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
||||||
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
|
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
|
||||||
const mediaType = lbry.getMediaType(
|
const mediaType = lbry.getMediaType(
|
||||||
|
@ -129,11 +113,7 @@ class Video extends React.PureComponent {
|
||||||
className="video__cover"
|
className="video__cover"
|
||||||
style={{ backgroundImage: 'url("' + metadata.thumbnail + '")' }}
|
style={{ backgroundImage: 'url("' + metadata.thumbnail + '")' }}
|
||||||
>
|
>
|
||||||
<VideoPlayButton
|
<VideoPlayButton {...this.props} mediaType={mediaType} />
|
||||||
startPlaying={this.startPlaying.bind(this)}
|
|
||||||
{...this.props}
|
|
||||||
mediaType={mediaType}
|
|
||||||
/>
|
|
||||||
</div>}
|
</div>}
|
||||||
{this.state.showNsfwHelp && <NsfwOverlay />}
|
{this.state.showNsfwHelp && <NsfwOverlay />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -70,6 +70,7 @@ export const CREATE_CHANNEL_COMPLETED = "CREATE_CHANNEL_COMPLETED";
|
||||||
export const PUBLISH_STARTED = "PUBLISH_STARTED";
|
export const PUBLISH_STARTED = "PUBLISH_STARTED";
|
||||||
export const PUBLISH_COMPLETED = "PUBLISH_COMPLETED";
|
export const PUBLISH_COMPLETED = "PUBLISH_COMPLETED";
|
||||||
export const PUBLISH_FAILED = "PUBLISH_FAILED";
|
export const PUBLISH_FAILED = "PUBLISH_FAILED";
|
||||||
|
export const SET_PLAYING_URI = "PLAY_URI";
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
export const FILE_LIST_STARTED = "FILE_LIST_STARTED";
|
export const FILE_LIST_STARTED = "FILE_LIST_STARTED";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { doCloseModal } from "actions/app";
|
import { doCloseModal } from "actions/app";
|
||||||
import { doLoadVideo } from "actions/content";
|
import { doLoadVideo, doSetPlayingUri } from "actions/content";
|
||||||
import { makeSelectMetadataForUri } from "selectors/claims";
|
import { makeSelectMetadataForUri } from "selectors/claims";
|
||||||
import ModalAffirmPurchase from "./view";
|
import ModalAffirmPurchase from "./view";
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ const select = (state, props) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
cancelPurchase: () => {
|
||||||
|
dispatch(doSetPlayingUri(null));
|
||||||
|
dispatch(doCloseModal());
|
||||||
|
},
|
||||||
closeModal: () => dispatch(doCloseModal()),
|
closeModal: () => dispatch(doCloseModal()),
|
||||||
loadVideo: uri => dispatch(doLoadVideo(uri)),
|
loadVideo: uri => dispatch(doLoadVideo(uri)),
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ModalAffirmPurchase extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { closeModal, metadata: { title }, uri } = this.props;
|
const { cancelPurchase, metadata: { title }, uri } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
@ -17,7 +17,7 @@ class ModalAffirmPurchase extends React.PureComponent {
|
||||||
isOpen={true}
|
isOpen={true}
|
||||||
contentLabel={__("Confirm Purchase")}
|
contentLabel={__("Confirm Purchase")}
|
||||||
onConfirmed={this.onAffirmPurchase.bind(this)}
|
onConfirmed={this.onAffirmPurchase.bind(this)}
|
||||||
onAborted={closeModal}
|
onAborted={cancelPurchase}
|
||||||
>
|
>
|
||||||
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
||||||
<strong>
|
<strong>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as types from "constants/action_types";
|
||||||
|
|
||||||
const reducers = {};
|
const reducers = {};
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
|
playingUri: null,
|
||||||
rewardedContentClaimIds: [],
|
rewardedContentClaimIds: [],
|
||||||
channelPages: {},
|
channelPages: {},
|
||||||
};
|
};
|
||||||
|
@ -58,6 +59,12 @@ reducers[types.RESOLVE_URI_CANCELED] = reducers[
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
reducers[types.SET_PLAYING_URI] = (state, action) => {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
playingUri: action.data.uri,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
// reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
||||||
// const channelPages = Object.assign({}, state.channelPages);
|
// const channelPages = Object.assign({}, state.channelPages);
|
||||||
// const { uri, claims } = action.data;
|
// const { uri, claims } = action.data;
|
||||||
|
|
|
@ -17,6 +17,11 @@ export const selectResolvingUris = createSelector(
|
||||||
state => state.resolvingUris || []
|
state => state.resolvingUris || []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectPlayingUri = createSelector(
|
||||||
|
_selectState,
|
||||||
|
state => state.playingUri
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectIsUriResolving = uri => {
|
export const makeSelectIsUriResolving = uri => {
|
||||||
return createSelector(
|
return createSelector(
|
||||||
selectResolvingUris,
|
selectResolvingUris,
|
||||||
|
|
Loading…
Reference in a new issue