2016-11-22 21:19:08 +01:00
import React from 'react' ;
2017-05-17 23:52:45 +02:00
import { FormField , FormRow } from 'component/form.js' ;
2017-05-05 07:48:15 +02:00
import SubHeader from 'component/subHeader'
2017-05-17 23:52:45 +02:00
import lbry from 'lbry.js' ;
2016-11-22 21:19:08 +01:00
2017-05-17 10:10:25 +02:00
class SettingsPage extends React . Component {
constructor ( props ) {
super ( props ) ;
const daemonSettings = this . props . daemonSettings
2017-05-18 03:37:39 +02:00
this . state = {
2017-05-17 10:10:25 +02:00
isMaxUpload : daemonSettings && daemonSettings . max _upload != 0 ,
isMaxDownload : daemonSettings && daemonSettings . max _download != 0 ,
showNsfw : lbry . getClientSetting ( 'showNsfw' ) ,
showUnavailable : lbry . getClientSetting ( 'showUnavailable' ) ,
}
}
setDaemonSetting ( name , value ) {
2017-05-17 23:52:45 +02:00
this . props . setDaemonSetting ( name , value )
2017-05-17 10:10:25 +02:00
}
setClientSetting ( name , value ) {
2017-04-12 16:55:19 +02:00
lbry . setClientSetting ( name , value )
this . _onSettingSaveSuccess ( )
2017-05-17 10:10:25 +02:00
}
onRunOnStartChange ( event ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'run_on_startup' , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
onShareDataChange ( event ) {
2017-05-03 19:56:39 +02:00
this . setDaemonSetting ( 'share_usage_data' , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
onDownloadDirChange ( event ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'download_directory' , event . target . value ) ;
2017-05-17 10:10:25 +02:00
}
onMaxUploadPrefChange ( isLimited ) {
2016-04-10 02:00:56 +02:00
if ( ! isLimited ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'max_upload' , 0.0 ) ;
2016-04-10 02:00:56 +02:00
}
this . setState ( {
isMaxUpload : isLimited
} ) ;
2017-05-17 10:10:25 +02:00
}
onMaxUploadFieldChange ( event ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'max_upload' , Number ( event . target . value ) ) ;
2017-05-17 10:10:25 +02:00
}
onMaxDownloadPrefChange ( isLimited ) {
2016-04-10 02:00:56 +02:00
if ( ! isLimited ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'max_download' , 0.0 ) ;
2016-04-10 02:00:56 +02:00
}
this . setState ( {
isMaxDownload : isLimited
} ) ;
2017-05-17 10:10:25 +02:00
}
onMaxDownloadFieldChange ( event ) {
2017-04-12 16:55:19 +02:00
this . setDaemonSetting ( 'max_download' , Number ( event . target . value ) ) ;
2017-05-17 10:10:25 +02:00
}
2017-05-17 23:52:45 +02:00
2017-05-17 10:10:25 +02:00
onShowNsfwChange ( event ) {
2016-08-22 21:19:04 +02:00
lbry . setClientSetting ( 'showNsfw' , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
onShowUnavailableChange ( event ) {
}
2017-04-12 16:55:19 +02:00
2017-05-17 10:10:25 +02:00
render ( ) {
2017-05-17 23:52:45 +02:00
const {
daemonSettings
} = this . props
if ( ! daemonSettings ) {
2017-05-26 08:40:35 +02:00
return < main className = "main--single-column" > < span className = "empty" > { _ _ ( "Failed to load settings." ) } < / span > < / main > ;
2016-04-10 02:00:56 +02:00
}
2017-04-12 22:23:20 +02:00
/ *
< section className = "card" >
< div className = "card__content" >
< h3 > Run on Startup < / h3 >
< / div >
< div className = "card__content" >
< FormRow type = "checkbox"
onChange = { this . onRunOnStartChange }
2017-05-17 23:52:45 +02:00
defaultChecked = { daemonSettings . run _on _startup }
2017-04-12 22:23:20 +02:00
label = "Run LBRY automatically when I start my computer" / >
< / div >
< / section >
* /
2016-04-10 02:00:56 +02:00
return (
2017-05-01 02:15:21 +02:00
< main className = "main--single-column" >
2017-05-05 07:48:15 +02:00
< SubHeader / >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< h3 > { _ _ ( "Download Directory" ) } < / h3 >
2017-04-10 14:32:40 +02:00
< / div >
< div className = "card__content" >
2017-05-12 12:39:32 +02:00
< FormRow type = "directory"
name = "download_directory"
2017-05-19 15:11:32 +02:00
defaultValue = { daemonSettings . download _directory }
2017-05-26 08:40:35 +02:00
helper = { _ _ ( "LBRY downloads will be saved here." ) }
2017-05-21 16:42:34 +02:00
onChange = { this . onDownloadDirChange . bind ( this ) } / >
2017-04-10 14:32:40 +02:00
< / div >
2016-04-10 02:00:56 +02:00
< / section >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< h3 > { _ _ ( "Bandwidth Limits" ) } < / h3 >
2017-04-10 14:32:40 +02:00
< / div >
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< div className = "form-row__label-row" > < div className = "form-field__label" > { _ _ ( "Max Upload" ) } < / div > < / div >
2017-04-10 20:12:07 +02:00
< FormRow type = "radio"
2017-04-10 14:32:40 +02:00
name = "max_upload_pref"
2017-04-30 03:56:55 +02:00
onChange = { ( ) => { this . onMaxUploadPrefChange ( false ) } }
2017-04-10 14:32:40 +02:00
defaultChecked = { ! this . state . isMaxUpload }
2017-05-26 08:40:35 +02:00
label = { _ _ ( "Unlimited" ) } / >
2017-04-12 16:55:19 +02:00
< div className = "form-row" >
< FormField type = "radio"
name = "max_upload_pref"
2017-04-30 03:56:55 +02:00
onChange = { ( ) => { this . onMaxUploadPrefChange ( true ) } }
2017-04-12 16:55:19 +02:00
defaultChecked = { this . state . isMaxUpload }
2017-05-26 08:40:35 +02:00
label = { this . state . isMaxUpload ? _ _ ( "Up to" ) : _ _ ( "Choose limit..." ) } / >
2017-04-12 16:55:19 +02:00
{ this . state . isMaxUpload ?
< FormField type = "number"
min = "0"
step = ".5"
2017-05-17 23:52:45 +02:00
defaultValue = { daemonSettings . max _upload }
2017-04-12 16:55:19 +02:00
placeholder = "10"
className = "form-field__input--inline"
2017-05-21 16:42:34 +02:00
onChange = { this . onMaxUploadFieldChange . bind ( this ) }
2017-04-12 16:55:19 +02:00
/ >
: ''
}
{ this . state . isMaxUpload ? < span className = "form-field__label" > MB / s < / span > : '' }
< / div >
2016-08-08 05:31:21 +02:00
< / div >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< div className = "form-row__label-row" > < div className = "form-field__label" > { _ _ ( "Max Download" ) } < / div > < / div >
< FormRow label = { _ _ ( "Unlimited" ) }
2017-04-10 20:12:07 +02:00
type = "radio"
name = "max_download_pref"
2017-04-30 03:56:55 +02:00
onChange = { ( ) => { this . onMaxDownloadPrefChange ( false ) } }
2017-04-10 20:12:07 +02:00
defaultChecked = { ! this . state . isMaxDownload } / >
2017-04-12 16:55:19 +02:00
< div className = "form-row" >
< FormField type = "radio"
name = "max_download_pref"
2017-04-30 03:56:55 +02:00
onChange = { ( ) => { this . onMaxDownloadPrefChange ( true ) } }
2017-04-12 16:55:19 +02:00
defaultChecked = { this . state . isMaxDownload }
2017-05-26 08:40:35 +02:00
label = { this . state . isMaxDownload ? _ _ ( "Up to" ) : _ _ ( "Choose limit..." ) } / >
2017-04-12 16:55:19 +02:00
{ this . state . isMaxDownload ?
< FormField type = "number"
min = "0"
step = ".5"
2017-05-17 23:52:45 +02:00
defaultValue = { daemonSettings . max _download }
2017-04-12 16:55:19 +02:00
placeholder = "10"
className = "form-field__input--inline"
2017-05-21 16:42:34 +02:00
onChange = { this . onMaxDownloadFieldChange . bind ( this ) }
2017-04-12 16:55:19 +02:00
/ >
: ''
}
{ this . state . isMaxDownload ? < span className = "form-field__label" > MB / s < / span > : '' }
< / div >
2016-08-08 05:31:21 +02:00
< / div >
2016-04-10 02:00:56 +02:00
< / section >
2016-08-22 21:19:04 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< h3 > { _ _ ( "Content" ) } < / h3 >
2016-08-22 22:56:52 +02:00
< / div >
2017-04-10 20:12:07 +02:00
< div className = "card__content" >
2017-04-10 14:32:40 +02:00
< FormRow type = "checkbox"
2017-05-21 16:42:34 +02:00
onChange = { this . onShowUnavailableChange . bind ( this ) }
2017-04-10 14:32:40 +02:00
defaultChecked = { this . state . showUnavailable }
2017-05-26 08:40:35 +02:00
label = { _ _ ( "Show unavailable content in search results" ) } / >
2017-01-19 10:58:11 +01:00
< / div >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< FormRow label = { _ _ ( "Show NSFW content" ) } type = "checkbox"
2017-05-21 16:42:34 +02:00
onChange = { this . onShowNsfwChange . bind ( this ) } defaultChecked = { this . state . showNsfw }
2017-05-26 08:40:35 +02:00
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
< / div >
< / section >
2016-08-08 00:45:26 +02:00
< section className = "card" >
2017-04-10 14:32:40 +02:00
< div className = "card__content" >
2017-05-26 08:40:35 +02:00
< h3 > { _ _ ( "Share Diagnostic Data" ) } < / h3 >
2017-04-10 14:32:40 +02:00
< / div >
2017-04-10 20:12:07 +02:00
< div className = "card__content" >
2017-04-10 14:32:40 +02:00
< FormRow type = "checkbox"
2017-05-21 16:42:34 +02:00
onChange = { this . onShareDataChange . bind ( this ) }
2017-05-17 23:52:45 +02:00
defaultChecked = { daemonSettings . share _usage _data }
2017-05-26 08:40:35 +02:00
label = { _ _ ( "Help make LBRY better by contributing diagnostic data about my usage" ) } / >
2017-04-10 14:32:40 +02:00
< / div >
2016-04-10 02:00:56 +02:00
< / section >
< / main >
) ;
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
export default SettingsPage ;