2020-04-15 14:58:06 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
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-04-18 11:58:51 -07:00
|
|
|
import { changeSetting } from 'gabsocial/actions/settings';
|
2020-04-15 14:58:06 -07:00
|
|
|
import Column from '../ui/components/column';
|
2020-04-20 17:33:19 -07:00
|
|
|
import { SimpleForm, FieldsGroup } from 'gabsocial/features/forms';
|
|
|
|
import SettingsCheckbox from './components/settings_checkbox';
|
2020-04-15 14:58:06 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
heading: { id: 'column.preferences', defaultMessage: 'Preferences' },
|
|
|
|
});
|
|
|
|
|
2020-04-16 14:13:22 -07:00
|
|
|
// TODO: Pull dynamically
|
|
|
|
const themes = {
|
|
|
|
cobalt: 'cobalt',
|
|
|
|
'gabsocial-light': 'Light',
|
|
|
|
default: 'Dark',
|
|
|
|
contrast: 'High contrast',
|
|
|
|
halloween: 'Halloween',
|
|
|
|
neenster: 'neenster',
|
|
|
|
glinner: 'glinner',
|
|
|
|
lime: 'lime',
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
settings: state.get('settings'),
|
|
|
|
});
|
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-04-16 14:13:22 -07:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = { isLoading: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
getFormData = (form) => {
|
|
|
|
return Object.fromEntries(
|
|
|
|
Array.from(form).map(i => [i.name, i.value])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onThemeChange = e => {
|
|
|
|
const { dispatch } = this.props;
|
2020-04-18 11:58:51 -07:00
|
|
|
dispatch(changeSetting(['theme'], 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-04-20 16:52:33 -07:00
|
|
|
handleCheckboxSetting = path => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
return (e) => {
|
|
|
|
dispatch(changeSetting(path, e.target.checked));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
return (
|
2020-04-16 14:13:22 -07:00
|
|
|
<Column icon='users' heading={intl.formatMessage(messages.heading)} backBtnSlim>
|
2020-04-20 17:33:19 -07:00
|
|
|
<SimpleForm onSubmit={this.handleSubmit}>
|
2020-04-20 16:52:33 -07:00
|
|
|
|
2020-04-20 17:33:19 -07:00
|
|
|
<FieldsGroup>
|
2020-04-20 13:18:35 -07:00
|
|
|
<div className='input with_label select optional user_setting_theme'>
|
|
|
|
<div className='label_input'>
|
|
|
|
<label className='select optional' htmlFor='user_setting_theme'>Site theme</label>
|
|
|
|
<div className='label_input__wrapper'>
|
|
|
|
<select
|
|
|
|
className='select optional'
|
|
|
|
name='user[setting_theme]'
|
|
|
|
id='user_setting_theme'
|
|
|
|
onChange={this.onThemeChange}
|
|
|
|
defaultValue={settings.get('theme')}
|
|
|
|
>
|
|
|
|
{Object.keys(themes).map(theme => (
|
|
|
|
<option key={theme} value={theme}>
|
|
|
|
{themes[theme]}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
2020-04-16 14:13:22 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-20 17:33:19 -07:00
|
|
|
</FieldsGroup>
|
2020-04-20 16:52:33 -07:00
|
|
|
|
2020-04-20 17:33:19 -07:00
|
|
|
<FieldsGroup>
|
2020-04-20 13:18:35 -07:00
|
|
|
<div className='input with_floating_label radio_buttons optional user_setting_default_privacy'>
|
|
|
|
<div className='label_input'>
|
|
|
|
<label className='radio_buttons optional'>Post privacy</label>
|
|
|
|
<ul>
|
|
|
|
<li className='radio'>
|
|
|
|
<label htmlFor='user_setting_default_privacy_public'>
|
|
|
|
<input className='radio_buttons optional' type='radio' checked={settings.get('defaultPrivacy') === 'public'} onChange={this.onDefaultPrivacyChange} value='public' id='user_setting_default_privacy_public' />Public
|
|
|
|
<span className='hint'>Everyone can see</span>
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
<li className='radio'>
|
|
|
|
<label htmlFor='user_setting_default_privacy_unlisted'>
|
|
|
|
<input className='radio_buttons optional' type='radio' checked={settings.get('defaultPrivacy') === 'unlisted'} onChange={this.onDefaultPrivacyChange} value='unlisted' id='user_setting_default_privacy_unlisted' />Unlisted
|
|
|
|
<span className='hint'>Everyone can see, but not listed on public timelines</span>
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
<li className='radio'>
|
|
|
|
<label htmlFor='user_setting_default_privacy_private'>
|
|
|
|
<input className='radio_buttons optional' type='radio' checked={settings.get('defaultPrivacy') === 'private'} onChange={this.onDefaultPrivacyChange} value='private' id='user_setting_default_privacy_private' />Followers-only
|
|
|
|
<span className='hint'>Only show to followers</span>
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-20 17:33:19 -07:00
|
|
|
</FieldsGroup>
|
|
|
|
|
|
|
|
<FieldsGroup>
|
|
|
|
<SettingsCheckbox
|
|
|
|
label='Show confirmation dialog before unfollowing someone'
|
|
|
|
path={['unfollowModal']}
|
|
|
|
/>
|
|
|
|
<SettingsCheckbox
|
|
|
|
label='Show confirmation dialog before reposting'
|
|
|
|
path={['boostModal']}
|
|
|
|
/>
|
|
|
|
<SettingsCheckbox
|
|
|
|
label='Show confirmation dialog before deleting a post'
|
|
|
|
path={['deleteModal']}
|
|
|
|
/>
|
|
|
|
</FieldsGroup>
|
|
|
|
|
|
|
|
</SimpleForm>
|
2020-04-16 14:13:22 -07:00
|
|
|
</Column>
|
2020-04-15 14:58:06 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|