From 20f79f1da54441fe22a172009d34734af1bd3807 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 09:49:45 +0900 Subject: [PATCH] Save settings by onBlur callback --- src/settings/actions/setting.js | 2 +- src/settings/components/form/BlacklistForm.jsx | 13 +++++++++++-- src/settings/components/form/KeymapsForm.jsx | 1 + src/settings/components/form/PropertiesForm.jsx | 1 + src/settings/components/form/SearchForm.jsx | 11 +++++++++-- src/settings/components/index.jsx | 11 +++++++++-- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/settings/actions/setting.js b/src/settings/actions/setting.js index 8844252..db63a45 100644 --- a/src/settings/actions/setting.js +++ b/src/settings/actions/setting.js @@ -60,4 +60,4 @@ const set = (settings) => { }; }; -export { load, save, switchToForm, switchToJson }; +export { load, save, set, switchToForm, switchToJson }; diff --git a/src/settings/components/form/BlacklistForm.jsx b/src/settings/components/form/BlacklistForm.jsx index cf7cffe..c470758 100644 --- a/src/settings/components/form/BlacklistForm.jsx +++ b/src/settings/components/form/BlacklistForm.jsx @@ -13,9 +13,13 @@ class BlacklistForm extends React.Component { return
+ onChange={this.bindValue.bind(this)} + onBlur={this.props.onBlur} + /> + onClick={this.bindValue.bind(this)} + onBlur={this.props.onBlur} + />
; }) } @@ -38,17 +42,22 @@ class BlacklistForm extends React.Component { } this.props.onChange(next); + if (name === 'delete') { + this.props.onBlur(); + } } } BlacklistForm.propTypes = { value: PropTypes.arrayOf(PropTypes.string), onChange: PropTypes.func, + onBlur: PropTypes.func, }; BlacklistForm.defaultProps = { value: [], onChange: () => {}, + onBlur: () => {}, }; export default BlacklistForm; diff --git a/src/settings/components/form/KeymapsForm.jsx b/src/settings/components/form/KeymapsForm.jsx index 5bb65cb..01acf61 100644 --- a/src/settings/components/form/KeymapsForm.jsx +++ b/src/settings/components/form/KeymapsForm.jsx @@ -20,6 +20,7 @@ class KeymapsForm extends React.Component { type='text' id={name} name={name} key={name} label={label} value={value} onChange={this.bindValue.bind(this)} + onBlur={this.props.onBlur} />; }) } diff --git a/src/settings/components/form/PropertiesForm.jsx b/src/settings/components/form/PropertiesForm.jsx index 0014899..979fdd8 100644 --- a/src/settings/components/form/PropertiesForm.jsx +++ b/src/settings/components/form/PropertiesForm.jsx @@ -27,6 +27,7 @@ class PropertiesForm extends React.Component { className='column-input' value={value[name] ? value[name] : ''} onChange={this.bindValue.bind(this)} + onBlur={this.props.onBlur} checked={value[name]} /> diff --git a/src/settings/components/form/SearchForm.jsx b/src/settings/components/form/SearchForm.jsx index d2f2d48..6b0bd01 100644 --- a/src/settings/components/form/SearchForm.jsx +++ b/src/settings/components/form/SearchForm.jsx @@ -23,11 +23,15 @@ class SearchForm extends React.Component { return
+ onChange={this.bindValue.bind(this)} + onBlur={this.props.onBlur} + /> + onChange={this.bindValue.bind(this)} + onBlur={this.props.onBlur} + />
this.bindForm('keymaps', value)} + onBlur={this.save.bind(this)} />
@@ -32,6 +33,7 @@ class SettingsComponent extends React.Component { this.bindForm('search', value)} + onBlur={this.save.bind(this)} />
@@ -39,6 +41,7 @@ class SettingsComponent extends React.Component { this.bindForm('blacklist', value)} + onBlur={this.save.bind(this)} />
@@ -47,6 +50,7 @@ class SettingsComponent extends React.Component { types={properties.types} value={form.properties} onChange={value => this.bindForm('properties', value)} + onBlur={this.save.bind(this)} />
; @@ -61,6 +65,7 @@ class SettingsComponent extends React.Component { spellCheck='false' error={error} onChange={this.bindJson.bind(this)} + onBlur={this.save.bind(this)} value={json} />
; @@ -109,7 +114,7 @@ class SettingsComponent extends React.Component { form: { ...this.props.form }, }; settings.form[name] = value; - this.props.dispatch(settingActions.save(settings)); + this.props.dispatch(settingActions.set(settings)); } bindJson(e) { @@ -118,7 +123,7 @@ class SettingsComponent extends React.Component { json: e.target.value, form: this.props.form, }; - this.props.dispatch(settingActions.save(settings)); + this.props.dispatch(settingActions.set(settings)); } bindSource(e) { @@ -135,7 +140,9 @@ class SettingsComponent extends React.Component { } this.props.dispatch(settingActions.switchToForm(this.props.json)); } + } + save() { let settings = this.props.store.getState(); this.props.dispatch(settingActions.save(settings)); }