2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-08-17 21:39:25 +01:00
import { connect } from 'react-redux'
2020-04-28 06:33:58 +01:00
import { injectIntl , defineMessages } from 'react-intl'
2020-04-30 05:34:50 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes'
2020-05-03 06:22:49 +01:00
import ImmutablePureComponent from 'react-immutable-pure-component'
import { changeSetting , saveSettings } from '../../actions/settings'
import {
DEFAULT _THEME ,
DEFAULT _FONT _SIZE ,
FONT _SIZES ,
} from '../../constants'
2020-04-30 05:34:50 +01:00
import ModalLayout from './modal_layout'
import Button from '../button'
import Text from '../text'
2020-09-02 19:21:11 +01:00
import Slider from '../slider'
2020-04-30 05:34:50 +01:00
import SettingSwitch from '../setting_switch'
2020-11-03 23:12:34 +00:00
import ResponsiveClassesComponent from '../../features/ui/util/responsive_classes_component'
2020-04-28 06:33:58 +01:00
2020-04-30 05:34:50 +01:00
class DisplayOptionsModal extends ImmutablePureComponent {
2020-04-28 06:33:58 +01:00
2020-09-02 19:21:11 +01:00
handleOnFontSizeChange = ( value ) => {
2020-05-03 06:22:49 +01:00
const fontSizeNames = Object . keys ( FONT _SIZES )
2020-09-02 19:21:11 +01:00
const index = fontSizeNames [ value ]
2020-05-03 06:22:49 +01:00
this . props . onChange ( 'fontSize' , index )
}
handleOnThemeSelected = ( e ) => {
this . props . onChange ( 'theme' , e . target . value )
2020-04-28 06:33:58 +01:00
}
2020-05-03 06:22:49 +01:00
handleOnRadiusKeyDisabled = ( key , checked ) => {
this . props . onChange ( key , checked )
2020-04-28 06:33:58 +01:00
}
render ( ) {
2020-04-30 05:34:50 +01:00
const {
2020-05-03 06:22:49 +01:00
fontSize ,
displayOptionsSettings ,
2020-04-30 05:34:50 +01:00
intl ,
2020-05-03 06:22:49 +01:00
theme ,
2020-04-30 05:34:50 +01:00
onClose ,
} = this . props
2020-05-03 06:22:49 +01:00
const fontSizeNames = Object . keys ( FONT _SIZES )
const currentFontSizeIndex = fontSizeNames . indexOf ( fontSize )
2020-04-28 06:33:58 +01:00
return (
< ModalLayout
2020-04-30 05:34:50 +01:00
onClose = { onClose }
width = { 520 }
2020-04-28 06:33:58 +01:00
title = { intl . formatMessage ( messages . title ) }
>
2020-04-30 05:34:50 +01:00
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . mb15 ] . join ( ' ' ) } >
2020-05-03 06:22:49 +01:00
< Text align = 'center' color = 'secondary' size = 'medium' >
2020-04-30 05:34:50 +01:00
{ intl . formatMessage ( messages . message ) }
< / T e x t >
< / d i v >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . mb15 ] . join ( ' ' ) } >
2020-05-03 06:22:49 +01:00
< Text weight = 'bold' size = 'small' color = 'secondary' >
2020-04-30 05:34:50 +01:00
Font Size
< / T e x t >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . radiusSmall , _s . mt10 , _s . py15 , _s . px15 , _s . bgTertiary ] . join ( ' ' ) } >
< div className = { [ _s . d , _s . flexRow , _s . aiCenter ] . join ( ' ' ) } >
< span className = { [ _s . d , _s . text , _s . cPrimary ] . join ( ' ' ) } style = { { fontSize : '12px' } } >
2020-05-03 06:22:49 +01:00
Aa
< / s p a n >
2020-09-02 19:21:11 +01:00
< Slider
2020-05-03 06:22:49 +01:00
min = '0'
value = { currentFontSizeIndex }
max = { fontSizeNames . length - 1 }
onInput = { this . handleOnFontSizeChange }
onChange = { this . handleOnFontSizeChange }
className = { [ _s . flexGrow1 , _s . outlineNone , _s . ml15 , _s . mr15 ] . join ( ' ' ) }
/ >
2020-08-18 21:49:11 +01:00
< span className = { [ _s . d , _s . text , _s . cPrimary ] . join ( ' ' ) } style = { { fontSize : '18px' } } >
2020-05-03 06:22:49 +01:00
Aa
< / s p a n >
< / d i v >
2020-04-30 05:34:50 +01:00
< / d i v >
< / d i v >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . mb15 ] . join ( ' ' ) } >
2020-05-03 06:22:49 +01:00
< Text weight = 'bold' size = 'small' color = 'secondary' >
2020-11-03 21:04:31 +00:00
Options
2020-04-30 05:34:50 +01:00
< / T e x t >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . radiusSmall , _s . mt10 , _s . py15 , _s . px15 , _s . bgTertiary ] . join ( ' ' ) } >
2020-04-30 05:34:50 +01:00
< SettingSwitch
2020-05-03 06:22:49 +01:00
prefix = 'displayOptions'
settings = { displayOptionsSettings }
settingPath = { 'radiusSmallDisabled' }
onChange = { this . handleOnRadiusKeyDisabled }
label = { 'Small Radius Disabled' }
2020-04-30 05:34:50 +01:00
/ >
< SettingSwitch
2020-05-03 06:22:49 +01:00
prefix = 'displayOptions'
settings = { displayOptionsSettings }
settingPath = { 'radiusCircleDisabled' }
onChange = { this . handleOnRadiusKeyDisabled }
label = { 'Circles Disabled' }
2020-04-30 05:34:50 +01:00
/ >
2020-11-03 21:04:31 +00:00
< SettingSwitch
prefix = 'displayOptions'
settings = { displayOptionsSettings }
settingPath = { 'logoDisabled' }
onChange = { this . handleOnRadiusKeyDisabled }
label = { 'Stealth Gab' }
/ >
2020-04-30 05:34:50 +01:00
< / d i v >
< / d i v >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . mb10 ] . join ( ' ' ) } >
2020-05-03 06:22:49 +01:00
< Text weight = 'bold' size = 'small' color = 'secondary' >
2020-04-30 05:34:50 +01:00
Theme
< / T e x t >
2020-11-03 23:12:34 +00:00
< div className = { [ _s . d , _s . radiusSmall , _s . flexRow , _s . flexWrap , _s . mt10 , _s . py10 , _s . bgTertiary ] . join ( ' ' ) } >
2020-05-03 06:22:49 +01:00
2020-11-03 21:12:24 +00:00
< ThemeBlock
title = 'White'
value = 'white'
checked = { theme === 'white' }
onChange = { this . handleOnThemeSelected }
style = { {
borderColor : '#ececed' ,
backgroundColor : '#fff' ,
color : '#2d3436' ,
} }
/ >
2020-05-03 06:22:49 +01:00
< ThemeBlock
title = 'Light'
value = 'light'
checked = { theme === 'light' }
onChange = { this . handleOnThemeSelected }
style = { {
2020-11-03 21:12:24 +00:00
borderColor : '#68D99F' ,
2020-05-03 06:22:49 +01:00
backgroundColor : '#fff' ,
color : '#2d3436' ,
} }
/ >
2020-04-30 05:34:50 +01:00
2020-05-03 06:22:49 +01:00
< ThemeBlock
title = 'Muted'
value = 'muted'
checked = { theme === 'muted' }
onChange = { this . handleOnThemeSelected }
style = { {
borderColor : '#424141' ,
backgroundColor : '#222' ,
color : '#fff' ,
} }
/ >
2020-04-30 05:34:50 +01:00
2020-05-03 06:22:49 +01:00
< ThemeBlock
title = 'Black'
value = 'black'
checked = { theme === 'black' }
onChange = { this . handleOnThemeSelected }
style = { {
borderColor : '#212020' ,
backgroundColor : '#13171b' ,
color : '#cccbcb' ,
} }
/ >
2020-04-30 05:34:50 +01:00
< / d i v >
< / d i v >
2020-05-03 06:22:49 +01:00
< div className = { [ _s . mlAuto , _s . my10 , _s . mrAuto ] . join ( ' ' ) } >
< Button onClick = { onClose } >
< Text size = 'medium' color = 'inherit' className = { _s . px10 } >
2020-04-30 05:34:50 +01:00
Done
< / T e x t >
< / B u t t o n >
< / d i v >
2020-05-03 06:22:49 +01:00
< / M o d a l L a y o u t >
2020-04-28 06:33:58 +01:00
)
}
}
2020-05-03 06:22:49 +01:00
2020-08-17 21:07:16 +01:00
class ThemeBlock extends React . PureComponent {
2020-05-03 06:22:49 +01:00
render ( ) {
const {
checked ,
onChange ,
title ,
value ,
style ,
} = this . props
const id = ` theme- ${ value } `
return (
2020-11-03 23:12:34 +00:00
< ResponsiveClassesComponent
classNames = { [ _s . d , _s . px10 , _s . flexGrow1 ] . join ( ' ' ) }
classNamesXS = { [ _s . d , _s . px10 , _s . flexGrow1 , _s . w48PC , _s . mb10 ] . join ( ' ' ) }
>
< label className = { [ _s . d , _s . w100PC ] . join ( ' ' ) } htmlFor = { id } >
2020-05-03 06:22:49 +01:00
< div
2020-08-18 21:49:11 +01:00
className = { [ _s . d , _s . borderBottom6PX , _s . aiCenter , _s . flexRow , _s . py10 , _s . px15 , _s . radiusSmall ] . join ( ' ' ) }
2020-05-03 06:22:49 +01:00
style = { style }
>
< input
type = 'radio'
name = 'theme'
value = { value }
id = { id }
checked = { checked }
onChange = { onChange }
/ >
< Text
align = 'center'
size = 'medium'
weight = 'bold'
color = 'inherit'
className = { [ _s . py10 , _s . flexGrow1 ] . join ( ' ' ) }
>
{ title }
< / T e x t >
< / d i v >
< / l a b e l >
2020-11-03 23:12:34 +00:00
< / R e s p o n s i v e C l a s s e s C o m p o n e n t >
2020-05-03 06:22:49 +01:00
)
}
2020-08-18 18:07:47 +01:00
}
2020-08-19 01:22:15 +01:00
ThemeBlock . propTypes = {
checked : PropTypes . bool ,
onChange : PropTypes . func . isRequired ,
title : PropTypes . string ,
value : PropTypes . string ,
style : PropTypes . object ,
}
2020-08-18 18:07:47 +01:00
const messages = defineMessages ( {
message : { id : 'display_options.message' , defaultMessage : 'Display settings affect your Gab account on this browser. These settings are only visible to you.' } ,
title : { id : 'display_options' , defaultMessage : 'Customize your view' } ,
} )
const mapStateToProps = ( state ) => ( {
displayOptionsSettings : state . getIn ( [ 'settings' , 'displayOptions' ] ) ,
fontSize : state . getIn ( [ 'settings' , 'displayOptions' , 'fontSize' ] , DEFAULT _FONT _SIZE ) ,
theme : state . getIn ( [ 'settings' , 'displayOptions' , 'theme' ] , DEFAULT _THEME ) ,
} )
const mapDispatchToProps = ( dispatch ) => ( {
onChange ( key , value ) {
dispatch ( changeSetting ( [ 'displayOptions' , key ] , value ) )
dispatch ( saveSettings ( ) )
} ,
} )
DisplayOptionsModal . propTypes = {
fontSize : PropTypes . string ,
intl : PropTypes . object . isRequired ,
onClose : PropTypes . func . isRequired ,
displayOptionsSettings : ImmutablePropTypes . map ,
theme : PropTypes . string ,
onChange : PropTypes . func . isRequired ,
onClose : PropTypes . func . isRequired ,
}
export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( DisplayOptionsModal ) )