2018-03-26 23:32:43 +02:00
// @flow
2019-07-08 22:54:58 +02:00
import * as PAGES from 'constants/pages' ;
2020-05-22 17:47:48 +02:00
import * as MODALS from 'constants/modal_types' ;
2020-06-19 22:18:12 +02:00
import * as ICONS from 'constants/icons' ;
2018-03-26 23:32:43 +02:00
import * as React from 'react' ;
2020-07-27 19:43:30 +02:00
import { SETTINGS } from 'lbry-redux' ;
import { FormField } from 'component/common/form' ;
2018-03-26 23:32:43 +02:00
import Button from 'component/button' ;
import Page from 'component/page' ;
2019-09-04 23:43:37 +02:00
import SettingLanguage from 'component/settingLanguage' ;
2018-03-26 23:32:43 +02:00
import FileSelector from 'component/common/file-selector' ;
2019-10-15 23:23:51 +02:00
import SyncToggle from 'component/syncToggle' ;
2020-11-10 17:07:00 +01:00
import HomepageSelector from 'component/homepageSelector' ;
2019-09-27 22:03:05 +02:00
import Card from 'component/common/card' ;
2020-04-13 21:16:07 +02:00
import SettingAccountPassword from 'component/settingAccountPassword' ;
2020-11-10 06:21:04 +01:00
import classnames from 'classnames' ;
2020-07-27 19:43:30 +02:00
import { getPasswordFromCookie } from 'util/saved-passwords' ;
2020-11-10 17:07:00 +01:00
// $FlowFixMe
import homepages from 'homepages' ;
2020-04-15 18:43:22 +02:00
import { Lbryio } from 'lbryinc' ;
2020-11-10 06:21:04 +01:00
import Yrbl from 'component/yrbl' ;
2019-11-18 19:30:15 +01:00
2019-04-24 16:02:08 +02:00
type Price = {
2018-03-26 23:32:43 +02:00
currency : string ,
amount : number ,
} ;
2020-07-27 19:43:30 +02:00
type SetDaemonSettingArg = boolean | string | number ;
2019-02-12 18:26:50 +01:00
2019-08-18 19:01:04 +02:00
type DarkModeTimes = {
from : { hour : string , min : string , formattedTime : string } ,
to : { hour : string , min : string , formattedTime : string } ,
} ;
type OptionTimes = {
fromTo : string ,
time : string ,
} ;
2018-03-26 23:32:43 +02:00
type DaemonSettings = {
2019-02-12 18:26:50 +01:00
download _dir : string ,
2018-03-26 23:32:43 +02:00
share _usage _data : boolean ,
} ;
type Props = {
2019-02-12 18:26:50 +01:00
setDaemonSetting : ( string , ? SetDaemonSettingArg ) => void ,
2021-03-03 19:50:16 +01:00
clearDaemonSetting : ( string ) => void ,
2019-02-12 18:26:50 +01:00
setClientSetting : ( string , SetDaemonSettingArg ) => void ,
2021-03-03 19:50:16 +01:00
toggle3PAnalytics : ( boolean ) => void ,
2018-03-26 23:32:43 +02:00
clearCache : ( ) => Promise < any > ,
daemonSettings : DaemonSettings ,
2020-02-19 07:31:40 +01:00
allowAnalytics : boolean ,
2018-03-26 23:32:43 +02:00
showNsfw : boolean ,
2019-11-22 22:13:00 +01:00
isAuthenticated : boolean ,
2018-03-26 23:32:43 +02:00
instantPurchaseEnabled : boolean ,
instantPurchaseMax : Price ,
currentTheme : string ,
themes : Array < string > ,
automaticDarkModeEnabled : boolean ,
2018-05-30 05:18:41 +02:00
autoplay : boolean ,
2018-10-13 17:49:47 +02:00
updateWalletStatus : ( ) => void ,
2018-07-18 21:48:30 +02:00
walletEncrypted : boolean ,
2019-09-26 18:28:08 +02:00
confirmForgetPassword : ( { } ) => void ,
2019-08-13 07:35:13 +02:00
floatingPlayer : boolean ,
2020-05-22 17:47:48 +02:00
hideReposts : ? boolean ,
2019-08-13 07:35:13 +02:00
clearPlayingUri : ( ) => void ,
2019-08-18 19:01:04 +02:00
darkModeTimes : DarkModeTimes ,
2019-08-18 18:54:55 +02:00
setDarkTime : ( string , { } ) => void ,
2021-03-03 19:50:16 +01:00
openModal : ( string ) => void ,
2020-06-27 18:48:25 +02:00
language ? : string ,
2020-09-04 17:02:30 +02:00
enterSettings : ( ) => void ,
exitSettings : ( ) => void ,
2018-03-26 23:32:43 +02:00
} ;
type State = {
clearingCache : boolean ,
2019-08-20 14:29:59 +02:00
storedPassword : boolean ,
2018-03-26 23:32:43 +02:00
} ;
class SettingsPage extends React . PureComponent < Props , State > {
constructor ( props : Props ) {
2017-05-17 10:10:25 +02:00
super ( props ) ;
2017-06-02 18:40:26 +02:00
2017-05-18 03:37:39 +02:00
this . state = {
2017-06-16 07:43:43 +02:00
clearingCache : false ,
2019-08-20 14:29:59 +02:00
storedPassword : false ,
2017-06-06 23:19:12 +02:00
} ;
2018-02-08 20:28:46 +01:00
2018-03-26 23:32:43 +02:00
( this : any ) . onThemeChange = this . onThemeChange . bind ( this ) ;
( this : any ) . onAutomaticDarkModeChange = this . onAutomaticDarkModeChange . bind ( this ) ;
2019-08-18 18:54:55 +02:00
( this : any ) . onChangeTime = this . onChangeTime . bind ( this ) ;
2019-08-28 04:35:07 +02:00
( this : any ) . onConfirmForgetPassword = this . onConfirmForgetPassword . bind ( this ) ;
2017-06-16 07:43:43 +02:00
}
2018-03-26 23:32:43 +02:00
componentDidMount ( ) {
2020-09-04 17:02:30 +02:00
const { isAuthenticated , enterSettings } = this . props ;
2020-07-27 19:43:30 +02:00
2020-01-15 05:34:28 +01:00
if ( isAuthenticated || ! IS _WEB ) {
2019-12-14 17:12:33 +01:00
this . props . updateWalletStatus ( ) ;
2021-03-03 19:50:16 +01:00
getPasswordFromCookie ( ) . then ( ( p ) => {
2019-12-19 23:35:12 +01:00
if ( typeof p === 'string' ) {
2019-12-14 17:12:33 +01:00
this . setState ( { storedPassword : true } ) ;
}
} ) ;
}
2020-09-04 17:02:30 +02:00
enterSettings ( ) ;
}
componentWillUnmount ( ) {
const { exitSettings } = this . props ;
exitSettings ( ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onThemeChange ( event : SyntheticInputEvent < * > ) {
2017-08-12 20:46:10 +02:00
const { value } = event . target ;
2018-02-08 20:28:46 +01:00
if ( value === 'dark' ) {
this . onAutomaticDarkModeChange ( false ) ;
}
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . THEME , value ) ;
2017-08-05 03:36:36 +02:00
}
2018-03-26 23:32:43 +02:00
onAutomaticDarkModeChange ( value : boolean ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . AUTOMATIC _DARK _MODE _ENABLED , value ) ;
2018-01-14 10:14:15 +01:00
}
2019-08-20 14:29:59 +02:00
onConfirmForgetPassword ( ) {
const { confirmForgetPassword } = this . props ;
2019-09-26 18:28:08 +02:00
confirmForgetPassword ( {
callback : ( ) => {
this . setState ( { storedPassword : false } ) ;
} ,
} ) ;
2019-08-20 14:29:59 +02:00
}
2019-08-18 19:01:04 +02:00
onChangeTime ( event : SyntheticInputEvent < * > , options : OptionTimes ) {
2019-08-18 18:54:55 +02:00
const { value } = event . target ;
this . props . setDarkTime ( value , options ) ;
}
to12Hour ( time : string ) {
const now = new Date ( 0 , 0 , 0 , Number ( time ) ) ;
const hour = now . toLocaleTimeString ( 'en-US' , { hour12 : true , hour : '2-digit' } ) ;
return hour ;
}
2019-02-12 18:26:50 +01:00
setDaemonSetting ( name : string , value : ? SetDaemonSettingArg ) : void {
2018-10-13 17:49:47 +02:00
this . props . setDaemonSetting ( name , value ) ;
}
2020-03-24 18:57:17 +01:00
clearDaemonSetting ( name : string ) : void {
this . props . clearDaemonSetting ( name ) ;
}
2017-05-17 10:10:25 +02:00
render ( ) {
2017-09-07 03:53:42 +02:00
const {
daemonSettings ,
2020-02-19 07:31:40 +01:00
allowAnalytics ,
2017-09-07 03:53:42 +02:00
showNsfw ,
2019-11-22 22:13:00 +01:00
isAuthenticated ,
2018-03-26 23:32:43 +02:00
currentTheme ,
2017-09-07 03:53:42 +02:00
themes ,
2018-01-14 10:14:15 +01:00
automaticDarkModeEnabled ,
2018-05-30 05:18:41 +02:00
autoplay ,
2018-07-18 21:48:30 +02:00
walletEncrypted ,
2019-10-15 06:20:12 +02:00
// autoDownload,
2019-02-13 17:27:20 +01:00
setDaemonSetting ,
setClientSetting ,
2020-02-19 07:31:40 +01:00
toggle3PAnalytics ,
2019-08-13 07:35:13 +02:00
floatingPlayer ,
2020-04-15 18:43:22 +02:00
hideReposts ,
2019-08-14 05:04:08 +02:00
clearPlayingUri ,
2019-08-18 18:54:55 +02:00
darkModeTimes ,
2019-10-16 07:01:18 +02:00
clearCache ,
2020-05-22 17:47:48 +02:00
openModal ,
2017-09-07 03:53:42 +02:00
} = this . props ;
2019-10-17 21:15:32 +02:00
const { storedPassword } = this . state ;
2018-03-26 23:32:43 +02:00
const noDaemonSettings = ! daemonSettings || Object . keys ( daemonSettings ) . length === 0 ;
2019-08-18 18:54:55 +02:00
const startHours = [ '18' , '19' , '20' , '21' ] ;
const endHours = [ '5' , '6' , '7' , '8' ] ;
2019-02-12 18:26:50 +01:00
2016-04-10 02:00:56 +02:00
return (
2020-07-10 23:04:36 +02:00
< Page
noFooter
noSideNavigation
backout = { {
title : _ _ ( 'Settings' ) ,
backLabel : _ _ ( 'Done' ) ,
} }
className = "card-stack"
>
2020-11-10 21:26:00 +01:00
< Card title = { _ _ ( 'Language' ) } actions = { < SettingLanguage / > } / >
{ homepages && Object . keys ( homepages ) . length > 1 && (
< Card title = { _ _ ( 'Homepage' ) } actions = { < HomepageSelector / > } / >
) }
2020-11-10 06:21:04 +01:00
{ ! isAuthenticated && IS _WEB && (
< div className = "main--empty" >
< Yrbl
type = "happy"
title = { _ _ ( 'Sign up for full control' ) }
subtitle = { _ _ ( 'Unlock new buttons that change things.' ) }
actions = {
< div className = "section__actions" >
< Button button = "primary" icon = { ICONS . SIGN _UP } label = { _ _ ( 'Sign Up' ) } navigate = { ` / $ / ${ PAGES . AUTH } ` } / >
< / div >
}
/ >
< / div >
) }
2019-08-26 20:32:45 +02:00
{ ! IS _WEB && noDaemonSettings ? (
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2020-05-18 23:17:26 +02:00
< div className = "card__title card__title--deprecated" > { _ _ ( 'Failed to load settings.' ) } < / div >
2018-03-26 23:32:43 +02:00
< / section >
) : (
2020-11-13 19:10:47 +01:00
< div className = { classnames ( 'card-stack' , { 'card--disabled' : IS _WEB && ! isAuthenticated } ) } >
2020-04-13 21:16:07 +02:00
{ isAuthenticated && < SettingAccountPassword / > }
2019-10-23 20:59:33 +02:00
{ /* @if TARGET='app' */ }
2019-09-27 22:03:05 +02:00
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Download directory' ) }
2019-09-27 22:03:05 +02:00
actions = {
< React.Fragment >
< FileSelector
type = "openDirectory"
currentPath = { daemonSettings . download _dir }
2019-10-07 22:02:32 +02:00
onFileChosen = { ( newDirectory : WebFile ) => {
setDaemonSetting ( 'download_dir' , newDirectory . path ) ;
2019-09-27 22:03:05 +02:00
} }
/ >
< p className = "help" > { _ _ ( 'LBRY downloads will be saved here.' ) } < / p >
< / React.Fragment >
}
/ >
< Card
2020-07-27 19:43:30 +02:00
title = { _ _ ( 'Sync' ) }
subtitle = {
2020-09-04 17:02:30 +02:00
walletEncrypted && ! storedPassword && storedPassword !== ''
? _ _ ( "To enable Sync, close LBRY completely and check 'Remember Password' during wallet unlock." )
2020-07-27 19:43:30 +02:00
: null
2019-09-27 22:03:05 +02:00
}
2020-09-04 17:02:30 +02:00
actions = { < SyncToggle disabled = { walletEncrypted && ! storedPassword && storedPassword !== '' } / > }
2019-09-27 22:03:05 +02:00
/ >
2020-04-25 01:53:57 +02:00
{ /* @endif */ }
2019-09-27 22:03:05 +02:00
2020-11-10 21:27:39 +01:00
< Card
title = { _ _ ( 'Appearance' ) }
actions = {
< React.Fragment >
< fieldset - section >
< FormField
name = "theme_select"
type = "select"
label = { _ _ ( 'Theme' ) }
onChange = { this . onThemeChange }
value = { currentTheme }
disabled = { automaticDarkModeEnabled }
>
2021-03-03 19:50:16 +01:00
{ themes . map ( ( theme ) => (
2020-11-10 21:27:39 +01:00
< option key = { theme } value = { theme } >
{ theme === 'light' ? _ _ ( 'Light' ) : _ _ ( 'Dark' ) }
< / option >
) ) }
< / FormField >
< / f i e l d s e t - s e c t i o n >
< fieldset - section >
< FormField
type = "checkbox"
name = "automatic_dark_mode"
onChange = { ( ) => this . onAutomaticDarkModeChange ( ! automaticDarkModeEnabled ) }
checked = { automaticDarkModeEnabled }
label = { _ _ ( 'Automatic dark mode' ) }
/ >
{ automaticDarkModeEnabled && (
< fieldset - group class = "fieldset-group--smushed" >
< FormField
type = "select"
name = "automatic_dark_mode_range"
2021-03-03 19:50:16 +01:00
onChange = { ( value ) => this . onChangeTime ( value , { fromTo : 'from' , time : 'hour' } ) }
2020-11-10 21:27:39 +01:00
value = { darkModeTimes . from . hour }
label = { _ _ ( 'From --[initial time]--' ) }
>
2021-03-03 19:50:16 +01:00
{ startHours . map ( ( time ) => (
2020-11-10 21:27:39 +01:00
< option key = { time } value = { time } >
{ this . to12Hour ( time ) }
< / option >
) ) }
< / FormField >
< FormField
type = "select"
name = "automatic_dark_mode_range"
label = { _ _ ( 'To --[final time]--' ) }
2021-03-03 19:50:16 +01:00
onChange = { ( value ) => this . onChangeTime ( value , { fromTo : 'to' , time : 'hour' } ) }
2020-11-10 21:27:39 +01:00
value = { darkModeTimes . to . hour }
>
2021-03-03 19:50:16 +01:00
{ endHours . map ( ( time ) => (
2020-11-10 21:27:39 +01:00
< option key = { time } value = { time } >
{ this . to12Hour ( time ) }
< / option >
) ) }
< / FormField >
< / f i e l d s e t - g r o u p >
) }
< / f i e l d s e t - s e c t i o n >
< / React.Fragment >
}
/ >
2019-09-27 22:03:05 +02:00
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Content settings' ) }
2019-09-27 22:03:05 +02:00
actions = {
< React.Fragment >
< FormField
type = "checkbox"
name = "floating_player"
onChange = { ( ) => {
setClientSetting ( SETTINGS . FLOATING _PLAYER , ! floatingPlayer ) ;
clearPlayingUri ( ) ;
} }
checked = { floatingPlayer }
label = { _ _ ( 'Floating video player' ) }
helper = { _ _ ( 'Keep content playing in the corner when navigating to a different page.' ) }
/ >
2019-02-20 06:20:29 +01:00
2019-09-27 22:03:05 +02:00
< FormField
type = "checkbox"
name = "autoplay"
onChange = { ( ) => setClientSetting ( SETTINGS . AUTOPLAY , ! autoplay ) }
checked = { autoplay }
label = { _ _ ( 'Autoplay media files' ) }
helper = { _ _ (
'Autoplay video and audio files when navigating to a file, as well as the next related item when a file finishes playing.'
) }
2018-04-11 00:05:30 +02:00
/ >
2019-05-08 03:29:30 +02:00
2020-04-15 18:43:22 +02:00
< FormField
2020-02-20 13:30:27 +01:00
type = "checkbox"
2020-04-15 18:43:22 +02:00
name = "hide_reposts"
2021-03-03 19:50:16 +01:00
onChange = { ( e ) => {
2020-04-15 18:43:22 +02:00
if ( isAuthenticated ) {
let param = e . target . checked ? { add : 'noreposts' } : { remove : 'noreposts' } ;
Lbryio . call ( 'user_tag' , 'edit' , param ) ;
}
2020-05-22 17:47:48 +02:00
setClientSetting ( SETTINGS . HIDE _REPOSTS , ! hideReposts ) ;
2020-02-20 13:30:27 +01:00
} }
2020-04-15 18:43:22 +02:00
checked = { hideReposts }
label = { _ _ ( 'Hide reposts' ) }
helper = { _ _ ( 'You will not see reposts by people you follow or receive email notifying about them.' ) }
/ >
2020-02-20 13:30:27 +01:00
2019-10-17 18:58:28 +02:00
{ / * < F o r m F i e l d
2019-10-08 18:25:33 +02:00
type = "checkbox"
name = "show_anonymous"
onChange = { ( ) => setClientSetting ( SETTINGS . SHOW _ANONYMOUS , ! showAnonymous ) }
checked = { showAnonymous }
label = { _ _ ( 'Show anonymous content' ) }
2019-10-15 19:29:27 +02:00
helper = { _ _ ( 'Anonymous content is published without a channel.' ) }
2019-10-17 18:58:28 +02:00
/> */ }
2019-10-08 18:25:33 +02:00
2019-09-27 22:03:05 +02:00
< FormField
type = "checkbox"
name = "show_nsfw"
2020-05-22 17:47:48 +02:00
onChange = { ( ) =>
! IS _WEB || showNsfw
? setClientSetting ( SETTINGS . SHOW _MATURE , ! showNsfw )
: openModal ( MODALS . CONFIRM _AGE )
}
2019-09-27 22:03:05 +02:00
checked = { showNsfw }
label = { _ _ ( 'Show mature content' ) }
helper = { _ _ (
'Mature content may include nudity, intense sexuality, profanity, or other adult content. By displaying mature content, you are affirming you are of legal age to view mature content in your country or jurisdiction. '
) }
/ >
< / React.Fragment >
}
/ >
2020-03-24 18:57:17 +01:00
{ /* @if TARGET='app' */ }
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Share usage and diagnostic data' ) }
2020-07-27 19:43:30 +02:00
subtitle = {
< React.Fragment >
{ _ _ (
` This is information like error logging, performance tracking, and usage statistics. It includes your IP address and basic system details, but no other identifying information (unless you sign in to lbry.tv) `
) } { ' ' }
< Button button = "link" label = { _ _ ( 'Learn more' ) } href = "https://lbry.com/privacypolicy" / >
< / React.Fragment >
2020-03-24 18:57:17 +01:00
}
actions = {
2020-07-27 19:43:30 +02:00
< >
< FormField
type = "checkbox"
name = "share_internal"
onChange = { ( ) => setDaemonSetting ( 'share_usage_data' , ! daemonSettings . share _usage _data ) }
checked = { daemonSettings . share _usage _data }
label = { < React.Fragment > { _ _ ( 'Allow the app to share data to LBRY.inc' ) } < / React.Fragment > }
helper = {
isAuthenticated
? _ _ ( 'Internal sharing is required while signed in.' )
: _ _ ( 'Internal sharing is required to participate in rewards programs.' )
}
disabled = { isAuthenticated && daemonSettings . share _usage _data }
2020-03-24 18:57:17 +01:00
/ >
2020-07-27 19:43:30 +02:00
< FormField
type = "checkbox"
name = "share_third_party"
2021-03-03 19:50:16 +01:00
onChange = { ( e ) => toggle3PAnalytics ( e . target . checked ) }
2020-07-27 19:43:30 +02:00
checked = { allowAnalytics }
label = { _ _ ( 'Allow the app to access third party analytics platforms' ) }
helper = { _ _ ( 'We use detailed analytics to improve all aspects of the LBRY experience.' ) }
/ >
< / >
2020-03-24 18:57:17 +01:00
}
/ >
{ /* @endif */ }
2019-09-27 22:03:05 +02:00
2020-07-27 19:43:30 +02:00
{ ( isAuthenticated || ! IS _WEB ) && (
< >
< Card
title = { _ _ ( 'Notifications' ) }
actions = {
< div className = "section__actions" >
< Button
button = "secondary"
label = { _ _ ( 'Manage' ) }
icon = { ICONS . SETTINGS }
navigate = { ` / $ / ${ PAGES . SETTINGS _NOTIFICATIONS } ` }
/ >
< / div >
}
/ >
< Card
2021-03-03 19:50:16 +01:00
title = { _ _ ( 'Blocked and muted channels' ) }
2020-07-27 19:43:30 +02:00
actions = {
< div className = "section__actions" >
< Button
button = "secondary"
label = { _ _ ( 'Manage' ) }
icon = { ICONS . SETTINGS }
2021-03-03 19:50:16 +01:00
navigate = { ` / $ / ${ PAGES . SETTINGS _BLOCKED _MUTED } ` }
2020-07-27 19:43:30 +02:00
/ >
< / div >
}
/ >
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Advanced settings' ) }
2020-07-27 19:43:30 +02:00
actions = {
< div className = "section__actions" >
< Button
button = "secondary"
label = { _ _ ( 'Manage' ) }
icon = { ICONS . SETTINGS }
navigate = { ` / $ / ${ PAGES . SETTINGS _ADVANCED } ` }
/ >
< / div >
}
/ >
< / >
) }
2019-11-18 19:30:15 +01:00
2019-09-27 22:03:05 +02:00
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Application cache' ) }
2019-09-27 22:03:05 +02:00
subtitle = {
2019-11-22 22:13:00 +01:00
< p className = "section__subtitle" >
2019-09-27 22:03:05 +02:00
{ _ _ (
2019-11-22 22:13:00 +01:00
'This will clear the application cache, and might fix issues you are having. Your wallet will not be affected. '
2019-09-27 22:03:05 +02:00
) }
2019-10-16 03:14:21 +02:00
< / p >
2019-09-27 22:03:05 +02:00
}
actions = {
< Button
2019-11-22 22:13:00 +01:00
button = "secondary"
2020-07-27 19:43:30 +02:00
icon = { ICONS . ALERT }
2019-09-27 22:03:05 +02:00
label = { this . state . clearingCache ? _ _ ( 'Clearing' ) : _ _ ( 'Clear Cache' ) }
2019-10-16 07:01:18 +02:00
onClick = { clearCache }
2019-09-27 22:03:05 +02:00
disabled = { this . state . clearingCache }
/ >
}
/ >
2019-03-18 06:06:41 +01:00
< / div >
2018-03-26 23:32:43 +02:00
) }
< / Page >
2016-04-10 02:00:56 +02:00
) ;
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
2020-07-27 19:43:30 +02:00
export default SettingsPage ;