Settings: change to react hooks + remove unneeded props.

master
Tom Hacohen 5 years ago
parent bf7590dd91
commit f3a533ab2d

@ -2,15 +2,14 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react'; import * as React from 'react';
import { connect, useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { History } from 'history';
import Select from '@material-ui/core/Select'; import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl'; import FormControl from '@material-ui/core/FormControl';
import InputLabel from '@material-ui/core/InputLabel'; import InputLabel from '@material-ui/core/InputLabel';
import { store, StoreState, SettingsType } from '../store'; import { store, StoreState } from '../store';
import { setSettings } from '../store/actions'; import { setSettings } from '../store/actions';
import Container from '../widgets/Container'; import Container from '../widgets/Container';
@ -36,23 +35,16 @@ function SecurityFingerprint() {
); );
} }
interface PropsType { export default React.memo(function Settings() {
history: History; const settings = useSelector((state: StoreState) => state.settings);
}
interface PropsTypeInner extends PropsType { function handleChange(event: React.ChangeEvent<any>) {
settings: SettingsType; const name = event.target.name;
} const value = event.target.value;
class Settings extends React.PureComponent<PropsTypeInner> { store.dispatch(setSettings({ ...settings, [name]: value }));
constructor(props: any) {
super(props);
this.onCancel = this.onCancel.bind(this);
this.handleChange = this.handleChange.bind(this);
} }
public render() {
const { settings } = this.props;
return ( return (
<> <>
<AppBarOverride title="Settings" /> <AppBarOverride title="Settings" />
@ -67,7 +59,7 @@ class Settings extends React.PureComponent<PropsTypeInner> {
<Select <Select
name="locale" name="locale"
value={settings.locale} value={settings.locale}
onChange={this.handleChange} onChange={handleChange}
> >
<MenuItem value="en-gb">English (United Kingdom)</MenuItem> <MenuItem value="en-gb">English (United Kingdom)</MenuItem>
<MenuItem value="en-us">English (United States)</MenuItem> <MenuItem value="en-us">English (United States)</MenuItem>
@ -76,27 +68,4 @@ class Settings extends React.PureComponent<PropsTypeInner> {
</Container> </Container>
</> </>
); );
} });
public onCancel() {
this.props.history.goBack();
}
private handleChange(event: React.ChangeEvent<any>) {
const name = event.target.name;
const value = event.target.value;
const { settings } = this.props;
store.dispatch(setSettings({ ...settings, [name]: value }));
}
}
const mapStateToProps = (state: StoreState, _props: PropsType) => {
return {
settings: state.settings,
};
};
export default connect(
mapStateToProps
)(Settings);

@ -214,10 +214,8 @@ export default withRouter(function SyncGate(props: RouteComponentProps<{}> & Pro
<Route <Route
path={routeResolver.getRoute('settings')} path={routeResolver.getRoute('settings')}
exact exact
render={({ history }) => ( render={() => (
<Settings <Settings />
history={history}
/>
)} )}
/> />
<Route <Route

Loading…
Cancel
Save