diff --git a/app/gabsocial/features/forms/index.js b/app/gabsocial/features/forms/index.js new file mode 100644 index 000000000..1eb13ac0e --- /dev/null +++ b/app/gabsocial/features/forms/index.js @@ -0,0 +1,81 @@ +import React from 'react'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import PropTypes from 'prop-types'; +import { v4 as uuidv4 } from 'uuid'; + +export class SimpleForm extends ImmutablePureComponent { + + static propTypes = { + children: PropTypes.node, + onSubmit: PropTypes.function, + } + + render() { + const { children, onSubmit } = this.props; + + return ( +
+ {children} +
+ ); + } + +} + +export class FieldsGroup extends ImmutablePureComponent { + + static propTypes = { + children: PropTypes.node, + } + + render() { + const { children } = this.props; + + return ( +
+ {children} +
+ ); + } + +} + +export class Checkbox extends ImmutablePureComponent { + + static propTypes = { + label: PropTypes.string, + checked: PropTypes.bool, + onChange: PropTypes.func, + } + + static defaultProps = { + checked: false, + } + + render() { + const { label, checked, onChange } = this.props; + const id = uuidv4(); + + return ( +
+
+ +
+ +
+
+
+ ); + } + +} diff --git a/app/gabsocial/features/preferences/components/settings_checkbox.js b/app/gabsocial/features/preferences/components/settings_checkbox.js new file mode 100644 index 000000000..55f52ca97 --- /dev/null +++ b/app/gabsocial/features/preferences/components/settings_checkbox.js @@ -0,0 +1,41 @@ +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'; +import { changeSetting } from 'gabsocial/actions/settings'; +import { Checkbox } from '../../forms'; + +const mapStateToProps = state => ({ + settings: state.get('settings'), +}); + +export default @connect(mapStateToProps) +class SettingsCheckbox extends ImmutablePureComponent { + + static propTypes = { + label: PropTypes.string, + path: PropTypes.array.isRequired, + settings: ImmutablePropTypes.map.isRequired, + } + + handleCheckboxSetting = path => { + const { dispatch } = this.props; + return (e) => { + dispatch(changeSetting(path, e.target.checked)); + }; + } + + render() { + const { label, path, settings } = this.props; + + return ( + + ); + } + +} diff --git a/app/gabsocial/features/preferences/index.js b/app/gabsocial/features/preferences/index.js index 30844deed..35454a7ec 100644 --- a/app/gabsocial/features/preferences/index.js +++ b/app/gabsocial/features/preferences/index.js @@ -6,6 +6,8 @@ import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { changeSetting } from 'gabsocial/actions/settings'; import Column from '../ui/components/column'; +import { SimpleForm, FieldsGroup } from 'gabsocial/features/forms'; +import SettingsCheckbox from './components/settings_checkbox'; const messages = defineMessages({ heading: { id: 'column.preferences', defaultMessage: 'Preferences' }, @@ -70,9 +72,9 @@ class Preferences extends ImmutablePureComponent { return ( -
+ -
+
@@ -93,9 +95,9 @@ class Preferences extends ImmutablePureComponent {
- + -
+
@@ -121,52 +123,24 @@ class Preferences extends ImmutablePureComponent {
-
+ -
+ + + + + -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
- - +
); }