import React from "react"; import { Icon, BusyMessage } from "component/common"; import FilePrice from "component/filePrice"; import { Modal } from "modal/modal"; import Link from "component/link"; import { ToolTip } from "component/tooltip"; import { DropDownMenu, DropDownMenuItem } from "component/menu"; import ModalRemoveFile from "modal/modalRemoveFile"; import * as modals from "constants/modal_types"; class FileActions extends React.PureComponent { constructor(props) { super(props); this.state = { forceShowActions: false, }; } componentWillMount() { this.checkAvailability(this.props.uri); } componentWillReceiveProps(nextProps) { this.checkAvailability(nextProps.uri); this.restartDownload(nextProps); } restartDownload(props) { const { downloading, fileInfo, uri, restartDownload } = props; if ( !downloading && fileInfo && !fileInfo.completed && fileInfo.written_bytes !== false && fileInfo.written_bytes < fileInfo.total_bytes ) { restartDownload(uri, fileInfo.outpoint); } } checkAvailability(uri) { if (!this._uri || uri !== this._uri) { this._uri = uri; this.props.checkAvailability(uri); } } onShowFileActionsRowClicked() { this.setState({ forceShowActions: true, }); } onAffirmPurchase() { this.props.closeModal(); this.props.loadVideo(this.props.uri); } handleSupportButtonClicked() { this.props.onTipShow(); } render() { const { fileInfo, isAvailable, platform, downloading, uri, openInFolder, openInShell, modal, openModal, closeModal, startDownload, costInfo, loading, claimIsMine, claimInfo, navigate, } = this.props; const metadata = fileInfo ? fileInfo.metadata : null, openInFolderMessage = platform.startsWith("Mac") ? __("Open in Finder") : __("Open in Folder"), showMenu = fileInfo && Object.keys(fileInfo).length > 0, title = metadata ? metadata.title : uri; let content; if (loading || downloading) { const progress = fileInfo && fileInfo.written_bytes ? fileInfo.written_bytes / fileInfo.total_bytes * 100 : 0, label = fileInfo ? progress.toFixed(0) + __("% complete") : __("Connecting..."), labelWithIcon = ( {label} ); content = (
{labelWithIcon}
{labelWithIcon}
); } else if (!fileInfo && isAvailable === undefined) { content = ; } else if (!fileInfo && !isAvailable && !this.state.forceShowActions) { content = (
{__("Content unavailable.")}
); } else if (fileInfo === null && !downloading) { if (!costInfo) { content = ; } else { content = ( { startDownload(uri); }} /> ); } } else if (fileInfo && fileInfo.download_path) { content = ( openInShell(fileInfo)} /> ); } else if (!fileInfo) { content = ; } else { console.log("handle this case of file action props?"); } return (
{content} {showMenu ?
openInFolder(fileInfo)} label={openInFolderMessage} /> {claimIsMine && navigate("/publish", { name: fileInfo.name })} label={__("Edit claim")} />} openModal(modals.CONFIRM_FILE_REMOVE)} label={__("Remove...")} />
: ""} {__("This will purchase")} {title} {__("for")}{" "} {" "} {__("credits")}. {__("LBRY was unable to download the stream")}{" "}{" "} {title}. {modal == modals.CONFIRM_FILE_REMOVE && }
); } } export default FileActions;