lbry-desktop/ui/js/component/fileActions/view.jsx

148 lines
5.2 KiB
React
Raw Normal View History

import React from 'react';
2017-05-15 05:50:59 +02:00
import {Icon,BusyMessage} from 'component/common';
import FilePrice from 'component/filePrice'
import {Modal} from 'component/modal';
import {FormField} from 'component/form';
2017-04-07 07:15:22 +02:00
import Link from 'component/link';
import {ToolTip} from 'component/tooltip';
import {DropDownMenu, DropDownMenuItem} from 'component/menu';
2017-05-15 05:50:59 +02:00
class FileActions extends React.Component {
constructor(props) {
super(props)
this.state = {
2017-05-15 05:50:59 +02:00
forceShowActions: false,
deleteChecked: false,
}
}
2017-05-15 05:50:59 +02:00
componentWillMount() {
this.checkAvailability(this.props.uri)
}
componentWillReceiveProps(nextProps) {
this.checkAvailability(nextProps.uri)
}
checkAvailability(uri) {
if (!this._uri || uri !== this._uri) {
this._uri = uri;
this.props.checkAvailability(uri)
}
}
onShowFileActionsRowClicked() {
this.setState({
forceShowActions: true,
});
}
handleDeleteCheckboxClicked(event) {
this.setState({
deleteChecked: event.target.checked,
})
}
onAffirmPurchase() {
this.props.closeModal()
2017-05-15 05:50:59 +02:00
this.props.loadVideo(this.props.uri)
}
render() {
const {
fileInfo,
2017-05-15 05:50:59 +02:00
isAvailable,
platform,
downloading,
uri,
deleteFile,
openInFolder,
openInShell,
modal,
openModal,
closeModal,
2017-05-15 05:50:59 +02:00
startDownload,
} = this.props
2017-05-15 05:50:59 +02:00
const deleteChecked = this.state.deleteChecked,
metadata = fileInfo ? fileInfo.metadata : null,
openInFolderMessage = platform.startsWith('Mac') ? __('Open in Finder') : __('Open in Folder'),
2017-05-15 05:50:59 +02:00
showMenu = fileInfo && Object.keys(fileInfo).length > 0,
title = metadata ? metadata.title : uri;
2017-05-15 05:50:59 +02:00
let content
if (downloading) {
2017-05-15 18:34:33 +02:00
const
progress = (fileInfo && fileInfo.written_bytes) ? fileInfo.written_bytes / fileInfo.total_bytes * 100 : 0,
label = fileInfo ? progress.toFixed(0) + __('% complete') : __('Connecting...'),
labelWithIcon = <span className="button__content"><Icon icon="icon-download" /><span>{label}</span></span>;
content = <div className="faux-button-block file-actions__download-status-bar button-set-item">
<div className="faux-button-block file-actions__download-status-bar-overlay" style={{ width: progress + '%' }}>{labelWithIcon}</div>
{labelWithIcon}
</div>
} else if (!fileInfo && isAvailable === undefined) {
2017-05-15 05:50:59 +02:00
content = <BusyMessage message={__("Checking availability")} />
2017-05-15 05:50:59 +02:00
2017-05-15 18:34:33 +02:00
} else if (!fileInfo && !isAvailable && !this.state.forceShowActions) {
2017-05-15 05:50:59 +02:00
content = <div>
<div className="button-set-item empty">{__("Content unavailable.")}</div>
<ToolTip label={__("Why?")}
body={__("The content on LBRY is hosted by its users. It appears there are no users connected that have this file at the moment.")}
2017-05-15 05:50:59 +02:00
className="button-set-item" />
<Link label={__("Try Anyway")} onClick={this.onShowFileActionsRowClicked.bind(this)} className="button-text button-set-item" />
2017-05-15 05:50:59 +02:00
</div>
} else if (fileInfo === null && !downloading) {
content = <Link button="text" label={__("Download")} icon="icon-download" onClick={() => { startDownload(uri) } } />;
2017-05-15 05:50:59 +02:00
} else if (fileInfo && fileInfo.download_path) {
content = <Link label={__("Open")} button="text" icon="icon-folder-open" onClick={() => openInShell(fileInfo)} />;
} else {
2017-05-15 05:50:59 +02:00
console.log('handle this case of file action props?');
console.log(this.props)
}
return (
2017-05-15 05:50:59 +02:00
<section className="file-actions">
{ content }
{ showMenu ?
<DropDownMenu>
<DropDownMenuItem key={0} onClick={() => openInFolder(fileInfo)} label={openInFolderMessage} />
<DropDownMenuItem key={1} onClick={() => openModal('confirmRemove')} label={__("Remove...")} />
</DropDownMenu> : '' }
<Modal type="confirm" isOpen={modal == 'affirmPurchase'}
contentLabel={__("Confirm Purchase")} onConfirmed={this.onAffirmPurchase.bind(this)} onAborted={this.props.closeModal}>
{__("This will purchase")} <strong>{title}</strong> {__("for")} <strong><FilePrice uri={uri} look="plain" /></strong> {__("credits")}.
2017-04-13 20:52:26 +02:00
</Modal>
<Modal isOpen={modal == 'notEnoughCredits'} contentLabel={__("Not enough credits")}
onConfirmed={closeModal}>
{__("You don't have enough LBRY credits to pay for this stream.")}
</Modal>
<Modal isOpen={modal == 'timedOut'} contentLabel={__("Download failed")}
onConfirmed={closeModal}>
{__("LBRY was unable to download the stream")} <strong>{uri}</strong>.
</Modal>
<Modal isOpen={modal == 'confirmRemove'}
contentLabel={__("Not enough credits")}
2017-05-15 05:50:59 +02:00
type="confirm"
confirmButtonLabel={__("Remove")}
onConfirmed={() => deleteFile(fileInfo.outpoint, deleteChecked)}
2017-05-15 05:50:59 +02:00
onAborted={closeModal}>
<p>{__("Are you sure you'd like to remove")} <cite>{title}</cite> {__("from LBRY?")}</p>
<label><FormField type="checkbox" checked={deleteChecked} onClick={this.handleDeleteCheckboxClicked.bind(this)} /> {__("Delete this file from my computer")}</label>
</Modal>
2017-05-15 05:50:59 +02:00
</section>
);
}
}
export default FileActions