2020-04-15 14:58:06 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
2020-06-06 13:36:00 -07:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2020-04-15 14:58:06 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import PropTypes from 'prop-types' ;
2020-04-16 14:13:22 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2020-12-24 12:20:07 -08:00
import { getSettings , changeSetting } from 'soapbox/actions/settings' ;
2020-04-15 14:58:06 -07:00
import Column from '../ui/components/column' ;
2020-04-20 18:20:07 -07:00
import {
SimpleForm ,
FieldsGroup ,
RadioGroup ,
RadioItem ,
2020-04-20 18:33:27 -07:00
SelectDropdown ,
2020-05-28 15:52:07 -07:00
} from 'soapbox/features/forms' ;
2020-07-20 16:18:54 -07:00
import SettingsCheckbox from 'soapbox/components/settings_checkbox' ;
2020-04-15 14:58:06 -07:00
2021-06-26 06:07:45 -07:00
export const languages = {
2020-06-04 18:01:00 -07:00
en : 'English' ,
ar : 'العربية' ,
ast : 'Asturianu' ,
bg : 'Български' ,
bn : 'বাংলা' ,
ca : 'Català' ,
co : 'Corsu' ,
cs : 'Čeština' ,
cy : 'Cymraeg' ,
da : 'Dansk' ,
de : 'Deutsch' ,
el : 'Ελληνικά' ,
eo : 'Esperanto' ,
es : 'Español' ,
eu : 'Euskara' ,
fa : 'فارسی' ,
fi : 'Suomi' ,
fr : 'Français' ,
ga : 'Gaeilge' ,
gl : 'Galego' ,
he : 'עברית' ,
hi : 'हिन्दी' ,
hr : 'Hrvatski' ,
hu : 'Magyar' ,
hy : 'Հայերեն' ,
id : 'Bahasa Indonesia' ,
io : 'Ido' ,
it : 'Italiano' ,
ja : '日本語' ,
ka : 'ქართული' ,
kk : 'Қазақша' ,
ko : '한국어' ,
lt : 'Lietuvių' ,
lv : 'Latviešu' ,
ml : 'മലയാളം' ,
ms : 'Bahasa Melayu' ,
nl : 'Nederlands' ,
no : 'Norsk' ,
oc : 'Occitan' ,
pl : 'Polski' ,
pt : 'Português' ,
'pt-BR' : 'Português do Brasil' ,
ro : 'Română' ,
ru : 'Русский' ,
sk : 'Slovenčina' ,
sl : 'Slovenščina' ,
sq : 'Shqip' ,
sr : 'Српски' ,
'sr-Latn' : 'Srpski (latinica)' ,
sv : 'Svenska' ,
ta : 'தமிழ்' ,
te : 'తెలుగు' ,
th : 'ไทย' ,
tr : 'Türkçe' ,
uk : 'Українська' ,
zh : '中文' ,
'zh-CN' : '简体中文' ,
'zh-HK' : '繁體中文(香港)' ,
'zh-TW' : '繁體中文(臺灣)' ,
} ;
2020-04-15 14:58:06 -07:00
const messages = defineMessages ( {
heading : { id : 'column.preferences' , defaultMessage : 'Preferences' } ,
2020-10-28 09:52:42 -07:00
display _media _default : { id : 'preferences.fields.display_media.default' , defaultMessage : 'Hide media marked as sensitive' } ,
display _media _hide _all : { id : 'preferences.fields.display_media.hide_all' , defaultMessage : 'Always hide media' } ,
display _media _show _all : { id : 'preferences.fields.display_media.show_all' , defaultMessage : 'Always show media' } ,
2020-04-15 14:58:06 -07:00
} ) ;
2020-04-16 14:13:22 -07:00
const mapStateToProps = state => ( {
2020-12-24 12:20:07 -08:00
settings : getSettings ( state ) ,
2020-04-16 14:13:22 -07:00
} ) ;
2020-04-15 14:58:06 -07:00
export default @ connect ( mapStateToProps )
@ injectIntl
class Preferences extends ImmutablePureComponent {
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
2020-04-16 14:13:22 -07:00
settings : ImmutablePropTypes . map ,
2020-04-15 14:58:06 -07:00
} ;
2020-06-04 16:32:46 -07:00
onSelectChange = path => {
return e => {
this . props . dispatch ( changeSetting ( path , e . target . value ) ) ;
} ;
} ;
2020-04-16 14:13:22 -07:00
2020-04-20 13:18:35 -07:00
onDefaultPrivacyChange = e => {
const { dispatch } = this . props ;
dispatch ( changeSetting ( [ 'defaultPrivacy' ] , e . target . value ) ) ;
}
2020-12-24 12:20:07 -08:00
onDefaultContentTypeChange = e => {
const { dispatch } = this . props ;
dispatch ( changeSetting ( [ 'defaultContentType' ] , e . target . value ) ) ;
}
2020-04-15 14:58:06 -07:00
render ( ) {
2020-04-16 14:13:22 -07:00
const { settings , intl } = this . props ;
2020-04-15 14:58:06 -07:00
2020-10-28 09:52:42 -07:00
const displayMediaOptions = {
default : intl . formatMessage ( messages . display _media _default ) ,
hide _all : intl . formatMessage ( messages . display _media _hide _all ) ,
show _all : intl . formatMessage ( messages . display _media _show _all ) ,
} ;
2020-04-15 14:58:06 -07:00
return (
2020-04-21 17:24:57 -07:00
< Column icon = 'cog' heading = { intl . formatMessage ( messages . heading ) } backBtnSlim >
2020-04-20 18:20:07 -07:00
< SimpleForm >
2020-06-04 16:32:46 -07:00
< FieldsGroup >
< SelectDropdown
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.language_label' defaultMessage = 'Language' / > }
2020-06-04 18:01:00 -07:00
items = { languages }
2020-06-04 19:22:58 -07:00
defaultValue = { settings . get ( 'locale' ) }
2020-06-04 16:32:46 -07:00
onChange = { this . onSelectChange ( [ 'locale' ] ) }
2020-04-20 18:33:27 -07:00
/ >
2020-04-20 17:33:19 -07:00
< / F i e l d s G r o u p >
2020-04-20 16:52:33 -07:00
2020-10-28 09:52:42 -07:00
< FieldsGroup >
< SelectDropdown
label = { < FormattedMessage id = 'preferences.fields.media_display_label' defaultMessage = 'Media display' / > }
items = { displayMediaOptions }
defaultValue = { settings . get ( 'displayMedia' ) }
onChange = { this . onSelectChange ( [ 'displayMedia' ] ) }
/ >
< / F i e l d s G r o u p >
2020-04-20 17:33:19 -07:00
< FieldsGroup >
2020-06-06 13:36:00 -07:00
< RadioGroup
label = { < FormattedMessage id = 'preferences.fields.privacy_label' defaultMessage = 'Post privacy' / > }
onChange = { this . onDefaultPrivacyChange }
>
2020-04-20 18:20:07 -07:00
< RadioItem
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.options.privacy_public' defaultMessage = 'Public' / > }
hint = { < FormattedMessage id = 'preferences.hints.privacy_public' defaultMessage = 'Everyone can see' / > }
2020-04-20 18:20:07 -07:00
checked = { settings . get ( 'defaultPrivacy' ) === 'public' }
value = 'public'
/ >
< RadioItem
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.options.privacy_unlisted' defaultMessage = 'Unlisted' / > }
hint = { < FormattedMessage id = 'preferences.hints.privacy_unlisted' defaultMessage = 'Everyone can see, but not listed on public timelines' / > }
2020-04-20 18:20:07 -07:00
checked = { settings . get ( 'defaultPrivacy' ) === 'unlisted' }
value = 'unlisted'
/ >
< RadioItem
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.options.privacy_followers_only' defaultMessage = 'Followers-only' / > }
hint = { < FormattedMessage id = 'preferences.hints.privacy_followers_only' defaultMessage = 'Only show to followers' / > }
2020-04-20 18:20:07 -07:00
checked = { settings . get ( 'defaultPrivacy' ) === 'private' }
value = 'private'
/ >
< / R a d i o G r o u p >
2020-04-20 17:33:19 -07:00
< / F i e l d s G r o u p >
2020-12-24 12:20:07 -08:00
< FieldsGroup >
< RadioGroup
label = { < FormattedMessage id = 'preferences.fields.content_type_label' defaultMessage = 'Post format' / > }
onChange = { this . onDefaultContentTypeChange }
>
< RadioItem
label = { < FormattedMessage id = 'preferences.options.content_type_plaintext' defaultMessage = 'Plain text' / > }
checked = { settings . get ( 'defaultContentType' ) === 'text/plain' }
value = 'text/plain'
/ >
< RadioItem
label = { < FormattedMessage id = 'preferences.options.content_type_markdown' defaultMessage = 'Markdown' / > }
2020-12-29 08:30:21 -08:00
hint = { < FormattedMessage id = 'preferences.hints.content_type_markdown' defaultMessage = 'Warning: experimental!' / > }
2020-12-24 12:20:07 -08:00
checked = { settings . get ( 'defaultContentType' ) === 'text/markdown' }
value = 'text/markdown'
/ >
< / R a d i o G r o u p >
< / F i e l d s G r o u p >
2020-04-20 17:33:19 -07:00
< FieldsGroup >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.unfollow_modal_label' defaultMessage = 'Show confirmation dialog before unfollowing someone' / > }
2020-04-20 17:33:19 -07:00
path = { [ 'unfollowModal' ] }
/ >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.boost_modal_label' defaultMessage = 'Show confirmation dialog before reposting' / > }
2020-04-20 17:33:19 -07:00
path = { [ 'boostModal' ] }
/ >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.delete_modal_label' defaultMessage = 'Show confirmation dialog before deleting a post' / > }
2020-04-20 17:33:19 -07:00
path = { [ 'deleteModal' ] }
/ >
2021-06-21 11:33:05 -07:00
< SettingsCheckbox
2021-06-21 13:12:12 -07:00
label = { < FormattedMessage id = 'preferences.fields.missing_description_modal_label' defaultMessage = 'Show confirmation dialog before sending a post without media descriptions' / > }
2021-06-21 11:33:05 -07:00
path = { [ 'missingDescriptionModal' ] }
/ >
2020-04-20 17:33:19 -07:00
< / F i e l d s G r o u p >
2020-04-20 18:56:32 -07:00
< FieldsGroup >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.auto_play_gif_label' defaultMessage = 'Auto-play animated GIFs' / > }
2020-04-20 18:56:32 -07:00
path = { [ 'autoPlayGif' ] }
/ >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.expand_spoilers_label' defaultMessage = 'Always expand posts marked with content warnings' / > }
2020-04-20 18:56:32 -07:00
path = { [ 'expandSpoilers' ] }
/ >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.reduce_motion_label' defaultMessage = 'Reduce motion in animations' / > }
2020-04-20 18:56:32 -07:00
path = { [ 'reduceMotion' ] }
/ >
2020-04-21 13:05:49 -07:00
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.system_font_label' defaultMessage = "Use system's default font" / > }
2020-04-21 13:05:49 -07:00
path = { [ 'systemFont' ] }
/ >
2020-04-21 13:10:45 -07:00
< div className = 'dyslexic' >
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.dyslexic_font_label' defaultMessage = 'Dyslexic mode' / > }
2020-04-21 13:10:45 -07:00
path = { [ 'dyslexicFont' ] }
/ >
< / d i v >
2020-09-25 13:39:54 -07:00
< SettingsCheckbox
label = { < FormattedMessage id = 'preferences.fields.halloween_label' defaultMessage = 'Halloween mode' / > }
2020-09-25 16:06:15 -07:00
hint = { < FormattedMessage id = 'preferences.hints.halloween' defaultMessage = 'Beware: SPOOKY! Supports light/dark toggle.' / > }
2020-09-25 13:39:54 -07:00
path = { [ 'halloween' ] }
/ >
2020-04-21 13:14:06 -07:00
< SettingsCheckbox
2020-06-06 13:36:00 -07:00
label = { < FormattedMessage id = 'preferences.fields.demetricator_label' defaultMessage = 'Use Demetricator' / > }
hint = { < FormattedMessage id = 'preferences.hints.demetricator' defaultMessage = 'Decrease social media anxiety by hiding all numbers from the site.' / > }
2020-04-21 13:14:06 -07:00
path = { [ 'demetricator' ] }
/ >
2020-04-20 18:56:32 -07:00
< / F i e l d s G r o u p >
2020-04-20 17:33:19 -07:00
< / S i m p l e F o r m >
2020-04-16 14:13:22 -07:00
< / C o l u m n >
2020-04-15 14:58:06 -07:00
) ;
}
}