Save settings by onBlur callback
This commit is contained in:
parent
fce2434dcd
commit
20f79f1da5
6 changed files with 32 additions and 7 deletions
|
@ -60,4 +60,4 @@ const set = (settings) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export { load, save, switchToForm, switchToJson };
|
export { load, save, set, switchToForm, switchToJson };
|
||||||
|
|
|
@ -13,9 +13,13 @@ class BlacklistForm extends React.Component {
|
||||||
return <div key={index} className='form-blacklist-form-row'>
|
return <div key={index} className='form-blacklist-form-row'>
|
||||||
<input data-index={index} type='text' name='url'
|
<input data-index={index} type='text' name='url'
|
||||||
className='column-url' value={url}
|
className='column-url' value={url}
|
||||||
onChange={this.bindValue.bind(this)} />
|
onChange={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
|
/>
|
||||||
<DeleteButton data-index={index} name='delete'
|
<DeleteButton data-index={index} name='delete'
|
||||||
onClick={this.bindValue.bind(this)} />
|
onClick={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
|
/>
|
||||||
</div>;
|
</div>;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -38,17 +42,22 @@ class BlacklistForm extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onChange(next);
|
this.props.onChange(next);
|
||||||
|
if (name === 'delete') {
|
||||||
|
this.props.onBlur();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlacklistForm.propTypes = {
|
BlacklistForm.propTypes = {
|
||||||
value: PropTypes.arrayOf(PropTypes.string),
|
value: PropTypes.arrayOf(PropTypes.string),
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
|
onBlur: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
BlacklistForm.defaultProps = {
|
BlacklistForm.defaultProps = {
|
||||||
value: [],
|
value: [],
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
|
onBlur: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BlacklistForm;
|
export default BlacklistForm;
|
||||||
|
|
|
@ -20,6 +20,7 @@ class KeymapsForm extends React.Component {
|
||||||
type='text' id={name} name={name} key={name}
|
type='text' id={name} name={name} key={name}
|
||||||
label={label} value={value}
|
label={label} value={value}
|
||||||
onChange={this.bindValue.bind(this)}
|
onChange={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
/>;
|
/>;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class PropertiesForm extends React.Component {
|
||||||
className='column-input'
|
className='column-input'
|
||||||
value={value[name] ? value[name] : ''}
|
value={value[name] ? value[name] : ''}
|
||||||
onChange={this.bindValue.bind(this)}
|
onChange={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
checked={value[name]}
|
checked={value[name]}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
|
@ -23,11 +23,15 @@ class SearchForm extends React.Component {
|
||||||
return <div key={index} className='form-search-form-row'>
|
return <div key={index} className='form-search-form-row'>
|
||||||
<input data-index={index} type='text' name='name'
|
<input data-index={index} type='text' name='name'
|
||||||
className='column-name' value={engine[0]}
|
className='column-name' value={engine[0]}
|
||||||
onChange={this.bindValue.bind(this)} />
|
onChange={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
|
/>
|
||||||
<input data-index={index} type='text' name='url'
|
<input data-index={index} type='text' name='url'
|
||||||
placeholder='http://example.com/?q={}'
|
placeholder='http://example.com/?q={}'
|
||||||
className='column-url' value={engine[1]}
|
className='column-url' value={engine[1]}
|
||||||
onChange={this.bindValue.bind(this)} />
|
onChange={this.bindValue.bind(this)}
|
||||||
|
onBlur={this.props.onBlur}
|
||||||
|
/>
|
||||||
<div className='column-option'>
|
<div className='column-option'>
|
||||||
<input data-index={index} type='radio' name='default'
|
<input data-index={index} type='radio' name='default'
|
||||||
checked={value.default === engine[0]}
|
checked={value.default === engine[0]}
|
||||||
|
@ -66,6 +70,9 @@ class SearchForm extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onChange(next);
|
this.props.onChange(next);
|
||||||
|
if (name === 'delete' || name === 'default') {
|
||||||
|
this.props.onBlur();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ class SettingsComponent extends React.Component {
|
||||||
<KeymapsForm
|
<KeymapsForm
|
||||||
value={form.keymaps}
|
value={form.keymaps}
|
||||||
onChange={value => this.bindForm('keymaps', value)}
|
onChange={value => this.bindForm('keymaps', value)}
|
||||||
|
onBlur={this.save.bind(this)}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -32,6 +33,7 @@ class SettingsComponent extends React.Component {
|
||||||
<SearchForm
|
<SearchForm
|
||||||
value={form.search}
|
value={form.search}
|
||||||
onChange={value => this.bindForm('search', value)}
|
onChange={value => this.bindForm('search', value)}
|
||||||
|
onBlur={this.save.bind(this)}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -39,6 +41,7 @@ class SettingsComponent extends React.Component {
|
||||||
<BlacklistForm
|
<BlacklistForm
|
||||||
value={form.blacklist}
|
value={form.blacklist}
|
||||||
onChange={value => this.bindForm('blacklist', value)}
|
onChange={value => this.bindForm('blacklist', value)}
|
||||||
|
onBlur={this.save.bind(this)}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@ -47,6 +50,7 @@ class SettingsComponent extends React.Component {
|
||||||
types={properties.types}
|
types={properties.types}
|
||||||
value={form.properties}
|
value={form.properties}
|
||||||
onChange={value => this.bindForm('properties', value)}
|
onChange={value => this.bindForm('properties', value)}
|
||||||
|
onBlur={this.save.bind(this)}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>;
|
</div>;
|
||||||
|
@ -61,6 +65,7 @@ class SettingsComponent extends React.Component {
|
||||||
spellCheck='false'
|
spellCheck='false'
|
||||||
error={error}
|
error={error}
|
||||||
onChange={this.bindJson.bind(this)}
|
onChange={this.bindJson.bind(this)}
|
||||||
|
onBlur={this.save.bind(this)}
|
||||||
value={json}
|
value={json}
|
||||||
/>
|
/>
|
||||||
</div>;
|
</div>;
|
||||||
|
@ -109,7 +114,7 @@ class SettingsComponent extends React.Component {
|
||||||
form: { ...this.props.form },
|
form: { ...this.props.form },
|
||||||
};
|
};
|
||||||
settings.form[name] = value;
|
settings.form[name] = value;
|
||||||
this.props.dispatch(settingActions.save(settings));
|
this.props.dispatch(settingActions.set(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
bindJson(e) {
|
bindJson(e) {
|
||||||
|
@ -118,7 +123,7 @@ class SettingsComponent extends React.Component {
|
||||||
json: e.target.value,
|
json: e.target.value,
|
||||||
form: this.props.form,
|
form: this.props.form,
|
||||||
};
|
};
|
||||||
this.props.dispatch(settingActions.save(settings));
|
this.props.dispatch(settingActions.set(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
bindSource(e) {
|
bindSource(e) {
|
||||||
|
@ -135,7 +140,9 @@ class SettingsComponent extends React.Component {
|
||||||
}
|
}
|
||||||
this.props.dispatch(settingActions.switchToForm(this.props.json));
|
this.props.dispatch(settingActions.switchToForm(this.props.json));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
let settings = this.props.store.getState();
|
let settings = this.props.store.getState();
|
||||||
this.props.dispatch(settingActions.save(settings));
|
this.props.dispatch(settingActions.save(settings));
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue