diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index e721fdb..afcd42d 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -2501,14 +2501,14 @@ export function saveAppConfig(_payload) { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(_payload), + body: JSON.stringify({ 'payload': _payload }), }) .catch(function(error) { console.log(error); dispatch(triggerToaster(true, 'saveAppConfig', 'Error', 'error')); }) .then(response => response.json()) - .then(json => dispatch(getAppConfigState(json))) + .then(json => dispatch(getAppConfig())) } } diff --git a/react/src/components/dashboard/settings.js b/react/src/components/dashboard/settings.js index 8c123bc..45bc964 100644 --- a/react/src/components/dashboard/settings.js +++ b/react/src/components/dashboard/settings.js @@ -20,9 +20,8 @@ import AddCoinOptionsACFiat from '../addcoin/addcoinOptionsACFiat'; /* TODO: 1) pre-select active coin in add node tab - 2) add agama config section - 3) add fiat section - 4) kickstart section + 2) add fiat section + 3) kickstart section */ class Settings extends React.Component { constructor(props) { @@ -32,16 +31,18 @@ class Settings extends React.Component { debugLinesCount: 10, debugTarget: 'iguana', activeTabHeight: '10px', - appSettings: [], + appSettings: {}, }; this.exportWifKeys = this.exportWifKeys.bind(this); this.updateInput = this.updateInput.bind(this); + this.updateInputSettings = this.updateInputSettings.bind(this); this.importWifKey = this.importWifKey.bind(this); this.readDebugLog = this.readDebugLog.bind(this); this.checkNodes = this.checkNodes.bind(this); this.addNode = this.addNode.bind(this); this.renderPeersList = this.renderPeersList.bind(this); this.renderSNPeersList = this.renderSNPeersList.bind(this); + this._saveAppConfig = this._saveAppConfig.bind(this); } componentDidMount() { @@ -50,10 +51,6 @@ class Settings extends React.Component { Store.dispatch(getAppInfo()); } - _saveAppConfig() { - Store.dispatch(saveAppConfig); - } - openTab(elemId, tab) { const _height = document.querySelector('#' + elemId + ' .panel-collapse .panel-body').offsetHeight; @@ -201,13 +198,43 @@ class Settings extends React.Component { } } + updateInputSettings(e) { + let _appSettings = this.state.appSettings; + _appSettings[e.target.name] = e.target.value; + + this.setState({ + appSettings: _appSettings, + }); + + console.log(this.state.appSettings); + } + + _saveAppConfig() { + const _appSettings = this.state.appSettings; + let _appSettingsPristine = Object.assign({}, this.props.Settings.appSettings); + + for (let key in _appSettings) { + if (key.indexOf('__') === -1) { + _appSettingsPristine[key] = _appSettings[key]; + // console.log('key changed: ' + key + ', value: ' + _appSettings[key]); + } else { + const _nestedKey = key.split('__'); + _appSettingsPristine[_nestedKey[0]][_nestedKey[1]] = _appSettings[key]; + // console.log('key changed: ' + _nestedKey[0] + '.' + _nestedKey[1] + ', value: ' + _appSettings[key]); + } + } + + // console.log('changed settings obj', _appSettingsPristine); + Store.dispatch(saveAppConfig(_appSettingsPristine)); + } + renderConfigEditForm() { - console.log(this.props.Settings.appSettings); let items = []; const _appConfig = this.props.Settings.appSettings; - for (let key in this.props.Settings.appSettings) { - if (Object.keys(this.props.Settings.appSettings[key]).length && key !== 'host') { + for (let key in _appConfig) { + console.log(); + if (typeof _appConfig[key] === 'object') { items.push( @@ -217,14 +244,14 @@ class Settings extends React.Component { ); - for (let _key in this.props.Settings.appSettings[key]) { + for (let _key in _appConfig[key]) { items.push( {_key} - + ); @@ -236,7 +263,7 @@ class Settings extends React.Component { {key} - + ); @@ -559,7 +586,7 @@ class Settings extends React.Component { - ) + ); } }