lbry-desktop/src/ui/component/fileDownloadLink/view.jsx

50 lines
1.4 KiB
React
Raw Normal View History

2018-05-21 22:30:00 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as ICONS from 'constants/icons';
import * as MODALS from 'constants/modal_types';
import React from 'react';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
2018-06-20 05:55:25 +02:00
import ToolTip from 'component/common/tooltip';
2017-09-08 05:15:05 +02:00
2018-05-21 22:30:00 +02:00
type Props = {
claimIsMine: boolean,
2018-05-21 22:30:00 +02:00
downloading: boolean,
loading: boolean,
2019-08-02 08:28:14 +02:00
isStreamable: boolean,
fileInfo: ?FileInfo,
openModal: (id: string, { path: string }) => void,
pause: () => void,
2018-05-21 22:30:00 +02:00
};
2019-08-02 08:28:14 +02:00
function FileDownloadLink(props: Props) {
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, isStreamable } = props;
2017-09-08 05:15:05 +02:00
2019-08-02 08:28:14 +02:00
if (!isStreamable && (loading || downloading)) {
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
const label =
fileInfo && fileInfo.written_bytes > 0
? __('Downloading: ') + progress.toFixed(0) + __('% complete')
: __('Connecting...');
2018-03-26 23:32:43 +02:00
2019-08-02 08:28:14 +02:00
return <span>{label}</span>;
}
2017-09-08 05:15:05 +02:00
2019-08-02 08:28:14 +02:00
if (fileInfo && fileInfo.download_path && fileInfo.completed) {
return (
<ToolTip label={__('Open file')}>
<Button
button="link"
icon={ICONS.EXTERNAL}
onClick={() => {
pause();
openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { path: fileInfo.download_path, isMine: claimIsMine });
}}
/>
</ToolTip>
);
2017-09-08 05:15:05 +02:00
}
2019-08-02 08:28:14 +02:00
return null;
2017-09-08 05:15:05 +02:00
}
export default FileDownloadLink;