bigbuffet-rw/app/soapbox/components/settings_checkbox.js

40 lines
965 B
JavaScript
Raw Normal View History

2020-04-20 17:33:19 -07:00
import React from 'react';
import { connect } from 'react-redux';
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
2020-05-28 15:52:07 -07:00
import { changeSetting } from 'soapbox/actions/settings';
import { Checkbox } from 'soapbox/features/forms';
2020-04-20 17:33:19 -07:00
const mapStateToProps = state => ({
settings: state.get('settings'),
});
export default @connect(mapStateToProps)
class SettingsCheckbox extends ImmutablePureComponent {
static propTypes = {
path: PropTypes.array.isRequired,
settings: ImmutablePropTypes.map.isRequired,
}
2020-04-22 20:08:12 -07:00
onChange = path => {
return e => {
this.props.dispatch(changeSetting(path, e.target.checked));
2020-04-20 17:33:19 -07:00
};
}
render() {
2020-04-22 20:08:12 -07:00
const { settings, path, ...props } = this.props;
2020-04-20 17:33:19 -07:00
return (
<Checkbox
checked={settings.getIn(path)}
2020-04-22 20:08:12 -07:00
onChange={this.onChange(path)}
2020-04-22 17:36:27 -07:00
{...props}
2020-04-20 17:33:19 -07:00
/>
);
}
}