2016-11-22 21:19:08 +01:00
import React from 'react' ;
2017-04-10 14:32:40 +02:00
import { FormField , FormRow } from '../component/form.js' ;
2016-11-22 21:19:08 +01:00
import lbry from '../lbry.js' ;
2016-04-10 02:00:56 +02:00
var SettingsPage = React . createClass ( {
onRunOnStartChange : function ( event ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'run_on_startup' , event . target . checked ) ;
2016-04-10 02:00:56 +02:00
} ,
onShareDataChange : function ( event ) {
2017-03-29 17:07:29 +02:00
lbry . setDaemonSetting ( 'share_debug_info' , event . target . checked ) ;
2016-04-10 02:00:56 +02:00
} ,
onDownloadDirChange : function ( event ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'download_directory' , event . target . value ) ;
2016-04-10 02:00:56 +02:00
} ,
onMaxUploadPrefChange : function ( isLimited ) {
if ( ! isLimited ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'max_upload' , 0.0 ) ;
2016-04-10 02:00:56 +02:00
}
this . setState ( {
isMaxUpload : isLimited
} ) ;
} ,
onMaxUploadFieldChange : function ( event ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'max_upload' , Number ( event . target . value ) ) ;
2016-04-10 02:00:56 +02:00
} ,
onMaxDownloadPrefChange : function ( isLimited ) {
if ( ! isLimited ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'max_download' , 0.0 ) ;
2016-04-10 02:00:56 +02:00
}
this . setState ( {
isMaxDownload : isLimited
} ) ;
} ,
onMaxDownloadFieldChange : function ( event ) {
2016-08-22 20:13:41 +02:00
lbry . setDaemonSetting ( 'max_download' , Number ( event . target . value ) ) ;
2016-04-10 02:00:56 +02:00
} ,
getInitialState : function ( ) {
return {
2016-08-22 22:14:58 +02:00
settings : null ,
2017-01-19 10:58:11 +01:00
showNsfw : lbry . getClientSetting ( 'showNsfw' ) ,
showUnavailable : lbry . getClientSetting ( 'showUnavailable' ) ,
2016-04-10 02:00:56 +02:00
}
} ,
2016-08-07 23:05:04 +02:00
componentDidMount : function ( ) {
document . title = "Settings" ;
} ,
2016-04-10 02:00:56 +02:00
componentWillMount : function ( ) {
2016-08-22 20:13:41 +02:00
lbry . getDaemonSettings ( function ( settings ) {
2016-04-10 02:00:56 +02:00
this . setState ( {
2016-08-22 22:14:58 +02:00
daemonSettings : settings ,
2016-04-10 02:00:56 +02:00
isMaxUpload : settings . max _upload != 0 ,
isMaxDownload : settings . max _download != 0
} ) ;
} . bind ( this ) ) ;
} ,
2016-08-22 21:19:04 +02:00
onShowNsfwChange : function ( event ) {
lbry . setClientSetting ( 'showNsfw' , event . target . checked ) ;
} ,
2017-01-19 10:58:11 +01:00
onShowUnavailableChange : function ( event ) {
lbry . setClientSetting ( 'showUnavailable' , event . target . checked ) ;
} ,
2016-04-10 02:00:56 +02:00
render : function ( ) {
2016-08-22 22:14:58 +02:00
if ( ! this . state . daemonSettings ) {
2016-04-10 02:00:56 +02:00
return null ;
}
return (
2016-08-08 00:45:26 +02:00
< main >
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< h3 > Run on Startup < / h 3 >
< / d i v >
< div className = "card__content" >
< FormRow type = "checkbox"
onChange = { this . onRunOnStartChange }
defaultChecked = { this . state . daemonSettings . run _on _startup }
label = "Run LBRY automatically when I start my computer" / >
< / d i v >
2016-04-10 02:00:56 +02:00
< / s e c t i o n >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< h3 > Download Directory < / h 3 >
< / d i v >
< div className = "card__content" >
< FormRow type = "text"
name = "download_directory"
defaultValue = { this . state . daemonSettings . download _directory }
helper = "LBRY downloads will be saved here."
onChange = { this . onDownloadDirChange } / >
< / d i v >
2016-04-10 02:00:56 +02:00
< / s e c t i o n >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< h3 > Bandwidth Limits < / h 3 >
< / d i v >
< div className = "card__content" >
2016-08-08 05:31:21 +02:00
< h4 > Max Upload < / h 4 >
2017-04-10 14:32:40 +02:00
< FormField type = "radio"
name = "max_upload_pref"
onChange = { this . onMaxUploadPrefChange . bind ( this , false ) }
defaultChecked = { ! this . state . isMaxUpload }
label = "Unlimited" / >
< FormField type = "radio"
name = "max_upload_pref"
onChange = { this . onMaxUploadPrefChange . bind ( this , true ) }
defaultChecked = { this . state . isMaxUpload }
label = { this . state . isMaxUpload ? 'Up to' : 'Choose limit...' } / >
{ this . state . isMaxUpload ?
< FormField type = "number"
min = "0"
step = ".5"
label = "MB/s"
onChange = { this . onMaxUploadFieldChange }
/ > : ' '
}
2016-08-08 05:31:21 +02:00
< / d i v >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2016-08-08 05:31:21 +02:00
< h4 > Max Download < / h 4 >
< label style = { settingsRadioOptionStyles } >
< input type = "radio" name = "max_download_pref" onChange = { this . onMaxDownloadPrefChange . bind ( this , false ) } defaultChecked = { ! this . state . isMaxDownload } / > Unlimited
< / l a b e l >
< label style = { settingsRadioOptionStyles } >
< input type = "radio" name = "max_download_pref" onChange = { this . onMaxDownloadPrefChange . bind ( this , true ) } defaultChecked = { this . state . isMaxDownload } / > { this . state . isMaxDownload ? 'Up to' : 'Choose limit...' }
2016-08-22 22:14:58 +02:00
< span className = { this . state . isMaxDownload ? '' : 'hidden' } > < input type = "number" min = "0" step = ".5" defaultValue = { this . state . daemonSettings . max _download } style = { settingsNumberFieldStyles } onChange = { this . onMaxDownloadFieldChange } / > MB / s < / s p a n >
2016-08-08 05:31:21 +02:00
< / l a b e l >
< / d i v >
2016-04-10 02:00:56 +02:00
< / s e c t i o n >
2016-08-22 21:19:04 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< h3 > Content < / h 3 >
2016-08-22 22:56:52 +02:00
< / d i v >
2017-04-10 14:32:40 +02:00
< div class = "card__content" >
< FormRow type = "checkbox"
onChange = { this . onShowUnavailableChange }
defaultChecked = { this . state . showUnavailable }
label = "Show unavailable content in search results" / >
2017-01-19 10:58:11 +01:00
< / d i v >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< FormRow label = "Show NSFW content" type = "checkbox"
onChange = { this . onShowNsfwChange } defaultChecked = { this . state . showNsfw }
helper = "NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. " / >
2017-01-19 10:58:11 +01:00
< / d i v >
< / s e c t i o n >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
< h3 > Share Diagnostic Data < / h 3 >
< / d i v >
< div class = "card__content" >
< FormRow type = "checkbox"
onChange = { this . onShareDataChange }
defaultChecked = { this . state . daemonSettings . share _debug _info }
label = "Help make LBRY better by contributing diagnostic data about my usage" / >
< / d i v >
2016-04-10 02:00:56 +02:00
< / s e c t i o n >
< / m a i n >
) ;
}
2016-08-21 22:59:32 +02:00
} ) ;
2016-11-22 21:19:08 +01:00
2017-04-10 14:32:40 +02:00
/ *
< section className = "card" >
< h3 > Search < / h 3 >
< div className = "form-row" >
< div className = "help" >
Would you like search results to include items that are not currently available for download ?
< / d i v >
< label style = { settingsCheckBoxOptionStyles } >
< input type = "checkbox" onChange = { this . onShowUnavailableChange } defaultChecked = { this . state . showUnavailable } / > Show unavailable content in search results
< / l a b e l >
< / d i v >
< / s e c t i o n >
< section className = "card" >
< h3 > Share Diagnostic Data < / h 3 >
< label style = { settingsCheckBoxOptionStyles } >
< input type = "checkbox" onChange = { this . onShareDataChange } defaultChecked = { this . state . daemonSettings . upload _log } / > Help make LBRY better by contributing diagnostic data about my usage
< / l a b e l >
< / s e c t i o n >
* /
2016-11-22 21:19:08 +01:00
export default SettingsPage ;