2017-01-13 03:03:34 +01:00
import React from 'react' ;
2017-05-15 05:50:59 +02:00
import { Icon , BusyMessage } from 'component/common' ;
2017-04-29 19:02:25 +02:00
import FilePrice from 'component/filePrice'
2017-04-29 11:50:29 +02:00
import { Modal } from 'component/modal' ;
import { FormField } from 'component/form' ;
2017-04-07 07:15:22 +02:00
import Link from 'component/link' ;
2017-04-29 11:50:29 +02:00
import { ToolTip } from 'component/tooltip' ;
import { DropDownMenu , DropDownMenuItem } from 'component/menu' ;
2017-01-13 03:03:34 +01:00
2017-05-15 05:50:59 +02:00
class FileActions extends React . Component {
2017-04-29 19:02:25 +02:00
constructor ( props ) {
super ( props )
this . state = {
2017-05-15 05:50:59 +02:00
forceShowActions : false ,
2017-01-13 03:03:34 +01:00
deleteChecked : false ,
}
2017-04-29 19:02:25 +02:00
}
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 ,
} ) ;
}
2017-04-29 19:02:25 +02:00
handleDeleteCheckboxClicked ( event ) {
2017-01-13 03:03:34 +01:00
this . setState ( {
deleteChecked : event . target . checked ,
2017-04-29 19:02:25 +02:00
} )
}
2017-05-01 06:51:19 +02:00
onAffirmPurchase ( ) {
this . props . closeModal ( )
2017-05-15 05:50:59 +02:00
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 ,
deleteFile ,
openInFolder ,
openInShell ,
modal ,
openModal ,
closeModal ,
2017-05-15 05:50:59 +02:00
startDownload ,
2017-05-28 16:24:10 +02:00
costInfo ,
2017-04-29 19:02:25 +02:00
} = this . props
2017-05-15 05:50:59 +02:00
const deleteChecked = this . state . deleteChecked ,
metadata = fileInfo ? fileInfo . metadata : null ,
2017-05-26 09:02:37 +02:00
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-04-29 19:02:25 +02:00
2017-05-15 05:50:59 +02:00
let content
2017-04-29 19:02:25 +02:00
2017-05-19 01:14:26 +02:00
if ( downloading ) {
2017-05-15 18:34:33 +02:00
2017-05-19 01:14:26 +02:00
const
progress = ( fileInfo && fileInfo . written _bytes ) ? fileInfo . written _bytes / fileInfo . total _bytes * 100 : 0 ,
2017-05-26 09:02:37 +02:00
label = fileInfo ? progress . toFixed ( 0 ) + _ _ ( '% complete' ) : _ _ ( 'Connecting...' ) ,
2017-05-19 01:14:26 +02:00
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
2017-05-26 09:02:37 +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-01-21 07:52:32 +01:00
2017-05-15 05:50:59 +02:00
content = < div >
2017-05-26 09:02:37 +02:00
< 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" / >
2017-05-26 09:02:37 +02:00
< 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 ) {
2017-05-28 16:24:10 +02:00
if ( ! costInfo ) {
2017-05-28 18:56:01 +02:00
content = < BusyMessage message = { _ _ ( "Fetching cost info" ) } / >
2017-05-28 16:24:10 +02:00
} else {
2017-05-28 18:56:01 +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-05-26 09:02:37 +02:00
content = < Link label = { _ _ ( "Open" ) } button = "text" icon = "icon-folder-open" onClick = { ( ) => openInShell ( fileInfo ) } / > ;
2017-01-13 03:03:34 +01:00
} else {
2017-05-15 05:50:59 +02:00
console . log ( 'handle this case of file action props?' ) ;
console . log ( this . props )
2017-01-13 03:03:34 +01:00
}
return (
2017-05-15 05:50:59 +02:00
< section className = "file-actions" >
{ content }
2017-01-13 03:03:34 +01:00
{ showMenu ?
< DropDownMenu >
2017-04-29 19:02:25 +02:00
< DropDownMenuItem key = { 0 } onClick = { ( ) => openInFolder ( fileInfo ) } label = { openInFolderMessage } / >
2017-05-26 09:02:37 +02:00
< DropDownMenuItem key = { 1 } onClick = { ( ) => openModal ( 'confirmRemove' ) } label = { _ _ ( "Remove..." ) } / >
2017-01-13 03:03:34 +01:00
< / DropDownMenu > : '' }
2017-04-29 19:02:25 +02:00
< Modal type = "confirm" isOpen = { modal == 'affirmPurchase' }
2017-05-31 12:55:32 +02:00
contentLabel = { _ _ ( "Confirm Purchase" ) } onConfirmed = { this . onAffirmPurchase . bind ( this ) } onAborted = { closeModal } >
2017-05-26 09:02:37 +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-05-26 09:02:37 +02:00
< Modal isOpen = { modal == 'notEnoughCredits' } contentLabel = { _ _ ( "Not enough credits" ) }
2017-04-29 19:02:25 +02:00
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-05-26 09:02:37 +02:00
< Modal isOpen = { modal == 'timedOut' } contentLabel = { _ _ ( "Download failed" ) }
2017-04-29 19:02:25 +02:00
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-04-29 19:02:25 +02:00
< Modal isOpen = { modal == 'confirmRemove' }
2017-05-26 09:02:37 +02:00
contentLabel = { _ _ ( "Not enough credits" ) }
2017-05-15 05:50:59 +02:00
type = "confirm"
2017-05-26 09:02:37 +02:00
confirmButtonLabel = { _ _ ( "Remove" ) }
2017-05-19 01:14:26 +02:00
onConfirmed = { ( ) => deleteFile ( fileInfo . outpoint , deleteChecked ) }
2017-05-15 05:50:59 +02:00
onAborted = { closeModal } >
2017-05-26 09:02:37 +02:00
< p > { _ _ ( "Are you sure you'd like to remove" ) } < cite > { title } < / cite > { _ _ ( "from LBRY?" ) } < / p >
2017-01-13 03:03:34 +01:00
2017-05-26 09:02:37 +02:00
< label > < FormField type = "checkbox" checked = { deleteChecked } onClick = { this . handleDeleteCheckboxClicked . bind ( this ) } / > { _ _ ( "Delete this file from my computer" ) } < / label >
2017-01-13 03:03:34 +01:00
< / Modal >
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-04-29 11:50:29 +02:00
export default FileActions