2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import { Icon, BusyMessage } from "component/common";
|
|
|
|
import FilePrice from "component/filePrice";
|
|
|
|
import { Modal } from "component/modal";
|
|
|
|
import Link from "component/link";
|
|
|
|
import { ToolTip } from "component/tooltip";
|
|
|
|
import { DropDownMenu, DropDownMenuItem } from "component/menu";
|
2017-07-02 20:23:38 +02:00
|
|
|
import ModalRemoveFile from "component/modalRemoveFile";
|
|
|
|
import * as modals from "constants/modal_types";
|
2017-01-13 03:03:34 +01:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class FileActions extends React.PureComponent {
|
2017-04-29 19:02:25 +02:00
|
|
|
constructor(props) {
|
2017-06-06 23:19:12 +02:00
|
|
|
super(props);
|
2017-04-29 19:02:25 +02:00
|
|
|
this.state = {
|
2017-05-15 05:50:59 +02:00
|
|
|
forceShowActions: false,
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
componentWillMount() {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.checkAvailability(this.props.uri);
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.checkAvailability(nextProps.uri);
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkAvailability(uri) {
|
|
|
|
if (!this._uri || uri !== this._uri) {
|
|
|
|
this._uri = uri;
|
2017-06-06 23:19:12 +02:00
|
|
|
this.props.checkAvailability(uri);
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onShowFileActionsRowClicked() {
|
|
|
|
this.setState({
|
|
|
|
forceShowActions: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-01 06:51:19 +02:00
|
|
|
onAffirmPurchase() {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.props.closeModal();
|
|
|
|
this.props.loadVideo(this.props.uri);
|
2017-05-01 06:51:19 +02:00
|
|
|
}
|
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
fileInfo,
|
2017-05-15 05:50:59 +02:00
|
|
|
isAvailable,
|
2017-04-29 19:02:25 +02:00
|
|
|
platform,
|
|
|
|
downloading,
|
|
|
|
uri,
|
|
|
|
openInFolder,
|
|
|
|
openInShell,
|
|
|
|
modal,
|
|
|
|
openModal,
|
|
|
|
closeModal,
|
2017-05-15 05:50:59 +02:00
|
|
|
startDownload,
|
2017-05-28 16:24:10 +02:00
|
|
|
costInfo,
|
2017-06-02 09:40:40 +02:00
|
|
|
loading,
|
2017-06-29 09:44:34 +02:00
|
|
|
claimIsMine,
|
2017-06-06 23:19:12 +02:00
|
|
|
} = this.props;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-07-02 20:23:38 +02:00
|
|
|
const metadata = fileInfo ? fileInfo.metadata : null,
|
2017-06-06 23:19:12 +02:00
|
|
|
openInFolderMessage = platform.startsWith("Mac")
|
|
|
|
? __("Open in Finder")
|
|
|
|
: __("Open in Folder"),
|
|
|
|
showMenu = fileInfo && Object.keys(fileInfo).length > 0,
|
|
|
|
title = metadata ? metadata.title : uri;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
let content;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-02 09:40:40 +02:00
|
|
|
if (loading || downloading) {
|
2017-07-02 20:23:38 +02:00
|
|
|
const progress = fileInfo && fileInfo.written_bytes
|
|
|
|
? fileInfo.written_bytes / fileInfo.total_bytes * 100
|
|
|
|
: 0,
|
2017-06-06 23:19:12 +02:00
|
|
|
label = fileInfo
|
|
|
|
? progress.toFixed(0) + __("% complete")
|
|
|
|
: __("Connecting..."),
|
|
|
|
labelWithIcon = (
|
|
|
|
<span className="button__content">
|
2017-06-29 09:44:34 +02:00
|
|
|
<Icon icon="icon-download" />
|
|
|
|
<span>
|
|
|
|
{label}
|
|
|
|
</span>
|
2017-06-06 23:19:12 +02:00
|
|
|
</span>
|
|
|
|
);
|
2017-06-06 06:21:55 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
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>
|
|
|
|
);
|
2017-05-19 01:14:26 +02:00
|
|
|
} else if (!fileInfo && isAvailable === undefined) {
|
2017-06-06 23:19:12 +02:00
|
|
|
content = <BusyMessage message={__("Checking availability")} />;
|
2017-05-15 18:34:33 +02:00
|
|
|
} else if (!fileInfo && !isAvailable && !this.state.forceShowActions) {
|
2017-06-06 23:19:12 +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."
|
|
|
|
)}
|
|
|
|
className="button-set-item"
|
|
|
|
/>
|
|
|
|
<Link
|
|
|
|
label={__("Try Anyway")}
|
|
|
|
onClick={this.onShowFileActionsRowClicked.bind(this)}
|
|
|
|
className="button-text button-set-item"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2017-07-24 19:31:15 +02:00
|
|
|
} else if (
|
|
|
|
(fileInfo === null || (fileInfo && fileInfo.written_bytes === 0)) &&
|
|
|
|
!downloading
|
|
|
|
) {
|
2017-05-28 16:24:10 +02:00
|
|
|
if (!costInfo) {
|
2017-06-06 23:19:12 +02:00
|
|
|
content = <BusyMessage message={__("Fetching cost info")} />;
|
2017-05-28 16:24:10 +02:00
|
|
|
} else {
|
2017-06-06 23:19:12 +02:00
|
|
|
content = (
|
|
|
|
<Link
|
|
|
|
button="text"
|
|
|
|
label={__("Download")}
|
|
|
|
icon="icon-download"
|
|
|
|
onClick={() => {
|
|
|
|
startDownload(uri);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2017-05-28 16:24:10 +02:00
|
|
|
}
|
2017-05-15 05:50:59 +02:00
|
|
|
} else if (fileInfo && fileInfo.download_path) {
|
2017-06-06 23:19:12 +02:00
|
|
|
content = (
|
|
|
|
<Link
|
|
|
|
label={__("Open")}
|
|
|
|
button="text"
|
|
|
|
icon="icon-folder-open"
|
|
|
|
onClick={() => openInShell(fileInfo)}
|
|
|
|
/>
|
|
|
|
);
|
2017-07-19 08:12:01 +02:00
|
|
|
} else if (!fileInfo) {
|
|
|
|
content = <BusyMessage message={__("Fetching file info")} />;
|
2017-01-13 03:03:34 +01:00
|
|
|
} else {
|
2017-06-06 23:19:12 +02:00
|
|
|
console.log("handle this case of file action props?");
|
2017-01-13 03:03:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-05-15 05:50:59 +02:00
|
|
|
<section className="file-actions">
|
2017-06-06 23:19:12 +02:00
|
|
|
{content}
|
|
|
|
{showMenu
|
|
|
|
? <DropDownMenu>
|
|
|
|
<DropDownMenuItem
|
|
|
|
key={0}
|
|
|
|
onClick={() => openInFolder(fileInfo)}
|
|
|
|
label={openInFolderMessage}
|
|
|
|
/>
|
|
|
|
<DropDownMenuItem
|
|
|
|
key={1}
|
2017-07-02 20:23:38 +02:00
|
|
|
onClick={() => openModal(modals.CONFIRM_FILE_REMOVE)}
|
2017-06-06 23:19:12 +02:00
|
|
|
label={__("Remove...")}
|
|
|
|
/>
|
|
|
|
</DropDownMenu>
|
|
|
|
: ""}
|
|
|
|
<Modal
|
|
|
|
type="confirm"
|
|
|
|
isOpen={modal == "affirmPurchase"}
|
|
|
|
contentLabel={__("Confirm Purchase")}
|
|
|
|
onConfirmed={this.onAffirmPurchase.bind(this)}
|
|
|
|
onAborted={closeModal}
|
|
|
|
>
|
2017-06-29 09:44:34 +02:00
|
|
|
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
|
|
|
<strong>
|
|
|
|
<FilePrice uri={uri} look="plain" />
|
|
|
|
</strong>{" "}
|
|
|
|
{__("credits")}.
|
2017-04-13 20:52:26 +02:00
|
|
|
</Modal>
|
2017-06-06 23:19:12 +02:00
|
|
|
<Modal
|
|
|
|
isOpen={modal == "notEnoughCredits"}
|
|
|
|
contentLabel={__("Not enough credits")}
|
|
|
|
onConfirmed={closeModal}
|
|
|
|
>
|
2017-05-26 09:02:37 +02:00
|
|
|
{__("You don't have enough LBRY credits to pay for this stream.")}
|
2017-01-13 03:03:34 +01:00
|
|
|
</Modal>
|
2017-06-06 23:19:12 +02:00
|
|
|
<Modal
|
|
|
|
isOpen={modal == "timedOut"}
|
|
|
|
contentLabel={__("Download failed")}
|
|
|
|
onConfirmed={closeModal}
|
|
|
|
>
|
2017-05-26 09:02:37 +02:00
|
|
|
{__("LBRY was unable to download the stream")} <strong>{uri}</strong>.
|
2017-01-13 03:03:34 +01:00
|
|
|
</Modal>
|
2017-07-02 20:23:38 +02:00
|
|
|
{modal == modals.CONFIRM_FILE_REMOVE &&
|
|
|
|
<ModalRemoveFile
|
|
|
|
uri={uri}
|
|
|
|
outpoint={fileInfo.outpoint}
|
|
|
|
title={title}
|
|
|
|
/>}
|
2017-05-15 05:50:59 +02:00
|
|
|
</section>
|
2017-01-13 03:03:34 +01:00
|
|
|
);
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FileActions;
|