import { injectIntl, defineMessages } from 'react-intl' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { changeSetting, saveSettings } from '../../actions/settings' import { DEFAULT_THEME, DEFAULT_FONT_SIZE, FONT_SIZES, } from '../../constants' import ModalLayout from './modal_layout' import Button from '../button' import Text from '../text' import SettingSwitch from '../setting_switch' 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()) }, }) export default @connect(mapStateToProps, mapDispatchToProps) @injectIntl class DisplayOptionsModal extends ImmutablePureComponent { static 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, } updateOnProps = [ 'fontSize', 'displayOptionsSettings', 'theme', ] handleOnFontSizeChange = (e) => { const fontSizeNames = Object.keys(FONT_SIZES) const index = fontSizeNames[e.target.value] this.props.onChange('fontSize', index) } handleOnThemeSelected = (e) => { this.props.onChange('theme', e.target.value) } handleOnRadiusKeyDisabled = (key, checked) => { this.props.onChange(key, checked) } render() { const { fontSize, displayOptionsSettings, intl, theme, onClose, } = this.props const fontSizeNames = Object.keys(FONT_SIZES) const currentFontSizeIndex = fontSizeNames.indexOf(fontSize) return (
{intl.formatMessage(messages.message)}
Font Size
Aa Aa
Rounded
Theme
) } } class ThemeBlock extends PureComponent { static propTypes = { checked: PropTypes.bool, onChange: PropTypes.func.isRequired, title: PropTypes.string, value: PropTypes.string, style: PropTypes.object, } render() { const { checked, onChange, title, value, style, } = this.props const id = `theme-${value}` return ( ) } }