cleanup FileDownloadLink
This commit is contained in:
parent
f86bb14591
commit
2f4395a9e3
2 changed files with 5 additions and 24 deletions
|
@ -5,7 +5,6 @@ import {
|
||||||
makeSelectLoadingForUri,
|
makeSelectLoadingForUri,
|
||||||
makeSelectCostInfoForUri,
|
makeSelectCostInfoForUri,
|
||||||
} from 'lbry-redux';
|
} from 'lbry-redux';
|
||||||
import { doFetchAvailability } from 'redux/actions/availability';
|
|
||||||
import { doOpenFileInShell } from 'redux/actions/file';
|
import { doOpenFileInShell } from 'redux/actions/file';
|
||||||
import { doPurchaseUri, doStartDownload } from 'redux/actions/content';
|
import { doPurchaseUri, doStartDownload } from 'redux/actions/content';
|
||||||
import { doPause } from 'redux/actions/media';
|
import { doPause } from 'redux/actions/media';
|
||||||
|
@ -20,7 +19,6 @@ const select = (state, props) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
checkAvailability: uri => dispatch(doFetchAvailability(uri)),
|
|
||||||
openInShell: path => dispatch(doOpenFileInShell(path)),
|
openInShell: path => dispatch(doOpenFileInShell(path)),
|
||||||
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
||||||
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
||||||
|
|
|
@ -11,31 +11,19 @@ type Props = {
|
||||||
total_bytes: number,
|
total_bytes: number,
|
||||||
outpoint: number,
|
outpoint: number,
|
||||||
download_path: string,
|
download_path: string,
|
||||||
|
completed: boolean,
|
||||||
},
|
},
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
costInfo: ?{},
|
costInfo: ?{},
|
||||||
restartDownload: (string, number) => void,
|
restartDownload: (string, number) => void,
|
||||||
checkAvailability: string => void,
|
|
||||||
openInShell: string => void,
|
openInShell: string => void,
|
||||||
purchaseUri: string => void,
|
purchaseUri: string => void,
|
||||||
doPause: () => void,
|
doPause: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileDownloadLink extends React.PureComponent<Props> {
|
class FileDownloadLink extends React.PureComponent<Props> {
|
||||||
componentWillMount() {
|
componentWillUpdate() {
|
||||||
this.checkAvailability(this.props.uri);
|
const { downloading, fileInfo, uri, restartDownload } = this.props;
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: Props) {
|
|
||||||
this.checkAvailability(nextProps.uri);
|
|
||||||
this.restartDownload(nextProps);
|
|
||||||
}
|
|
||||||
|
|
||||||
uri: ?string;
|
|
||||||
|
|
||||||
restartDownload = (props: Props) => {
|
|
||||||
const { downloading, fileInfo, uri, restartDownload } = props;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!downloading &&
|
!downloading &&
|
||||||
fileInfo &&
|
fileInfo &&
|
||||||
|
@ -45,15 +33,10 @@ class FileDownloadLink extends React.PureComponent<Props> {
|
||||||
) {
|
) {
|
||||||
restartDownload(uri, fileInfo.outpoint);
|
restartDownload(uri, fileInfo.outpoint);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
checkAvailability(uri: string) {
|
|
||||||
if (!this.uri || uri !== this.uri) {
|
|
||||||
this.uri = uri;
|
|
||||||
this.props.checkAvailability(uri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uri: ?string;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
fileInfo,
|
fileInfo,
|
||||||
|
|
Loading…
Reference in a new issue