Merge pull request #3541 from matrix-org/t3chguy/fix_150rc1

SettingsFlag always run ToggleSwitch fully-controlled
This commit is contained in:
Michael Telatynski 2019-10-10 09:39:33 +01:00 committed by GitHub
commit 7160922b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,7 +30,6 @@ module.exports = createReactClass({
label: PropTypes.string, // untranslated label: PropTypes.string, // untranslated
onChange: PropTypes.func, onChange: PropTypes.func,
isExplicit: PropTypes.bool, isExplicit: PropTypes.bool,
manualSave: PropTypes.bool,
}, },
getInitialState: function() { getInitialState: function() {
@ -47,8 +46,8 @@ module.exports = createReactClass({
onChange: function(checked) { onChange: function(checked) {
if (this.props.group && !checked) return; if (this.props.group && !checked) return;
if (!this.props.manualSave) this.save(checked); this.save(checked);
else this.setState({ value: checked }); this.setState({ value: checked });
if (this.props.onChange) this.props.onChange(checked); if (this.props.onChange) this.props.onChange(checked);
}, },
@ -62,13 +61,6 @@ module.exports = createReactClass({
}, },
render: function() { render: function() {
const value = this.props.manualSave ? this.state.value : SettingsStore.getValueAt(
this.props.level,
this.props.name,
this.props.roomId,
this.props.isExplicit,
);
const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId, this.props.level); const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId, this.props.level);
let label = this.props.label; let label = this.props.label;
@ -78,7 +70,7 @@ module.exports = createReactClass({
return ( return (
<div className="mx_SettingsFlag"> <div className="mx_SettingsFlag">
<span className="mx_SettingsFlag_label">{label}</span> <span className="mx_SettingsFlag_label">{label}</span>
<ToggleSwitch checked={value} onChange={this.onChange} disabled={!canChange} aria-label={label} /> <ToggleSwitch checked={this.state.value} onChange={this.onChange} disabled={!canChange} aria-label={label} />
</div> </div>
); );
}, },