diff --git a/app/plugins/core/settings/Settings/index.js b/app/plugins/core/settings/Settings/index.js index 756ec40b..1e202dfa 100644 --- a/app/plugins/core/settings/Settings/index.js +++ b/app/plugins/core/settings/Settings/index.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react' +import React, { useState } from 'react' import PropTypes from 'prop-types' import { FormComponents } from '@cerebroapp/cerebro-ui' import loadThemes from 'lib/loadThemes' @@ -11,98 +11,79 @@ const { Select, Checkbox, Wrapper, Text } = FormComponents -class Settings extends Component { - constructor(props) { - super(props) - const { get } = this.props - this.state = { - hotkey: get('hotkey'), - showInTray: get('showInTray'), - country: get('country'), - theme: get('theme'), - proxy: get('proxy'), - developerMode: get('developerMode'), - cleanOnHide: get('cleanOnHide'), - pluginsSettings: get('plugins'), - trackingEnabled: get('trackingEnabled'), - crashreportingEnabled: get('crashreportingEnabled'), - openAtLogin: get('openAtLogin') - } - this.changeConfig = this.changeConfig.bind(this) - } +function Settings({ get, set }) { + const [state, setState] = useState(() => ({ + hotkey: get('hotkey'), + showInTray: get('showInTray'), + country: get('country'), + theme: get('theme'), + proxy: get('proxy'), + developerMode: get('developerMode'), + cleanOnHide: get('cleanOnHide'), + pluginsSettings: get('plugins'), + crashreportingEnabled: get('crashreportingEnabled'), + openAtLogin: get('openAtLogin') + })) - changeConfig(key, value) { - this.props.set(key, value) - this.setState({ - [key]: value - }) + const changeConfig = (key, value) => { + set(key, value) + setState((prevState) => ({ ...prevState, [key]: value })) } - render() { - const { - hotkey, showInTray, country, theme, proxy, developerMode, cleanOnHide, openAtLogin, - trackingEnabled, crashreportingEnabled - } = this.state - - return ( -
- - this.changeConfig('hotkey', key)} - /> - - this.changeConfig('theme', value)} - /> - this.changeConfig('proxy', value)} - /> - this.changeConfig('openAtLogin', value)} - /> - this.changeConfig('showInTray', value)} + return ( +
+ + changeConfig('hotkey', key)} /> - this.changeConfig('developerMode', value)} - /> - this.changeConfig('cleanOnHide', value)} - /> - this.changeConfig('trackingEnabled', value)} - /> - this.changeConfig('crashreportingEnabled', value)} - /> -
- ) - } + + changeConfig('theme', value)} + /> + changeConfig('proxy', value)} + /> + changeConfig('openAtLogin', value)} + /> + changeConfig('showInTray', value)} + /> + changeConfig('developerMode', value)} + /> + changeConfig('cleanOnHide', value)} + /> + changeConfig('crashreportingEnabled', value)} + /> +
+ ) } Settings.propTypes = {