1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00

All: Improved the way settings are changed. Should also fixed issue with sync context being accidentally broken.

This commit is contained in:
Laurent Cozic 2018-02-13 18:26:33 +00:00
parent ef0cc5e33e
commit 214a39c3d3
5 changed files with 58 additions and 61 deletions

View File

@ -15,10 +15,6 @@ class ConfigScreenComponent extends React.Component {
constructor() {
super();
this.state = {
settings: {},
};
shared.init(this);
this.checkSyncConfig_ = async () => {
@ -68,9 +64,7 @@ class ConfigScreenComponent extends React.Component {
};
const updateSettingValue = (key, value) => {
const settings = Object.assign({}, this.state.settings);
settings[key] = Setting.formatValue(key, value);
this.setState({ settings: settings });
return shared.updateSettingValue(this, key, value);
}
// Component key needs to be key+value otherwise it doesn't update when the settings change.
@ -142,10 +136,7 @@ class ConfigScreenComponent extends React.Component {
}
onSaveClick() {
for (let n in this.state.settings) {
if (!this.state.settings.hasOwnProperty(n)) continue;
Setting.setValue(n, this.state.settings[n]);
}
shared.saveSettings(this);
this.props.dispatch({ type: 'NAV_BACK' });
}
@ -167,24 +158,11 @@ class ConfigScreenComponent extends React.Component {
};
const buttonStyle = {
display: this.state.settings === this.props.settings ? 'none' : 'inline-block',
display: this.state.changedSettingKeys.length ? 'inline-block' : 'none',
marginRight: 10,
}
let settingComps = [];
let keys = Setting.keys(true, 'desktop');
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!(key in settings)) {
console.warn('Missing setting: ' + key);
continue;
}
const md = Setting.settingMetadata(key);
if (md.show && !md.show(settings)) continue;
const comp = this.settingToComponent(key, settings[key]);
if (!comp) continue;
settingComps.push(comp);
}
const settingComps = shared.settingsToComponents(this, 'desktop', settings);
const syncTargetMd = SyncTargetRegistry.idToMetadata(settings['sync.target']);

View File

@ -110,6 +110,7 @@ Select the "WebDAV" synchronisation target and follow the same instructions as f
Known compatible services that use WebDAV:
- [Box.com](https://www.box.com/)
- [DriveHQ](https://www.drivehq.com)
- [Zimbra](https://www.zimbra.com/)

View File

@ -20,11 +20,6 @@ class ConfigScreenComponent extends BaseScreenComponent {
super();
this.styles_ = {};
this.state = {
settings: {},
settingsChanged: false,
};
shared.init(this);
this.checkSyncConfig_ = async () => {
@ -32,11 +27,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
}
this.saveButton_press = () => {
for (let n in this.state.settings) {
if (!this.state.settings.hasOwnProperty(n)) continue;
Setting.setValue(n, this.state.settings[n]);
}
this.setState({settingsChanged:false});
return shared.saveSettings(this);
};
}
@ -113,12 +104,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
let output = null;
const updateSettingValue = (key, value) => {
const settings = Object.assign({}, this.state.settings);
settings[key] = Setting.formatValue(key, value);
this.setState({
settings: settings,
settingsChanged: true,
});
return shared.updateSettingValue(this, key, value);
}
const md = Setting.settingMetadata(key);
@ -187,20 +173,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
render() {
const settings = this.state.settings;
const keys = Setting.keys(true, 'mobile');
let settingComps = [];
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
//if (key == 'sync.target' && !settings.showAdvancedOptions) continue;
if (!Setting.isPublic(key)) continue;
const md = Setting.settingMetadata(key);
if (md.show && !md.show(settings)) continue;
const comp = this.settingToComponent(key, settings[key]);
if (!comp) continue;
settingComps.push(comp);
}
const settingComps = shared.settingsToComponents(this, 'mobile', settings);
const syncTargetMd = SyncTargetRegistry.idToMetadata(settings['sync.target']);
@ -244,7 +217,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
<ScreenHeader
title={_('Configuration')}
showSaveButton={true}
saveButtonDisabled={!this.state.settingsChanged}
saveButtonDisabled={!this.state.changedSettingKeys.length}
onSaveButtonPress={this.saveButton_press}
/>
<ScrollView >

View File

@ -7,6 +7,8 @@ const shared = {}
shared.init = function(comp) {
if (!comp.state) comp.state = {};
comp.state.checkSyncConfigResult = null;
comp.state.settings = {};
comp.state.changedSettingKeys = [];
}
shared.checkSyncConfig = async function(comp, settings) {
@ -34,4 +36,46 @@ shared.checkSyncConfigMessages = function(comp) {
return output;
}
shared.updateSettingValue = function(comp, key, value) {
const settings = Object.assign({}, comp.state.settings);
const changedSettingKeys = comp.state.changedSettingKeys.slice();
settings[key] = Setting.formatValue(key, value);
if (changedSettingKeys.indexOf(key) < 0) changedSettingKeys.push(key);
comp.setState({
settings: settings,
changedSettingKeys: changedSettingKeys,
});
}
shared.saveSettings = function(comp) {
for (let key in comp.state.settings) {
if (!comp.state.settings.hasOwnProperty(key)) continue;
if (comp.state.changedSettingKeys.indexOf(key) < 0) continue;
console.info("Saving", key, comp.state.settings[key]);
Setting.setValue(key, comp.state.settings[key]);
}
comp.setState({ changedSettingKeys: [] });
}
shared.settingsToComponents = function(comp, device, settings) {
const keys = Setting.keys(true, device);
const settingComps = [];
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!Setting.isPublic(key)) continue;
const md = Setting.settingMetadata(key);
if (md.show && !md.show(settings)) continue;
const settingComp = comp.settingToComponent(key, settings[key]);
if (!settingComp) continue;
settingComps.push(settingComp);
}
return settingComps
}
module.exports = shared;

View File

@ -310,6 +310,7 @@ sudo ln -s ~/.joplin-bin/bin/joplin /usr/bin/joplin
<p>Select the &quot;WebDAV&quot; synchronisation target and follow the same instructions as for Nextcloud above.</p>
<p>Known compatible services that use WebDAV:</p>
<ul>
<li><a href="https://www.box.com/">Box.com</a></li>
<li><a href="https://www.drivehq.com">DriveHQ</a></li>
<li><a href="https://www.zimbra.com/">Zimbra</a></li>
</ul>
@ -390,14 +391,14 @@ $$
<td><img src="https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/hr.png" alt=""></td>
<td>Croatian</td>
<td>hr_HR</td>
<td>Hrvoje Mandić <a href="&#x6d;&#x61;&#105;&#x6c;&#x74;&#111;&#x3a;&#116;&#114;&#98;&#x75;&#104;&#x6f;&#x6d;&#x40;&#110;&#101;&#116;&#46;&#x68;&#x72;">&#116;&#114;&#98;&#x75;&#104;&#x6f;&#x6d;&#x40;&#110;&#101;&#116;&#46;&#x68;&#x72;</a></td>
<td>Hrvoje Mandić <a href="&#x6d;&#97;&#105;&#x6c;&#x74;&#111;&#58;&#x74;&#x72;&#98;&#x75;&#x68;&#111;&#x6d;&#64;&#x6e;&#101;&#x74;&#x2e;&#104;&#114;">&#x74;&#x72;&#98;&#x75;&#x68;&#111;&#x6d;&#64;&#x6e;&#101;&#x74;&#x2e;&#104;&#114;</a></td>
<td>72%</td>
</tr>
<tr>
<td><img src="https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/de.png" alt=""></td>
<td>Deutsch</td>
<td>de_DE</td>
<td>Tobias Strobel <a href="&#109;&#97;&#x69;&#x6c;&#116;&#111;&#58;&#x67;&#x69;&#116;&#64;&#x73;&#x74;&#114;&#111;&#x62;&#x65;&#x6c;&#x74;&#111;&#x62;&#x69;&#97;&#x73;&#x2e;&#100;&#101;">&#x67;&#x69;&#116;&#64;&#x73;&#x74;&#114;&#111;&#x62;&#x65;&#x6c;&#x74;&#111;&#x62;&#x69;&#97;&#x73;&#x2e;&#100;&#101;</a></td>
<td>Tobias Strobel <a href="&#109;&#x61;&#105;&#x6c;&#x74;&#x6f;&#58;&#x67;&#x69;&#x74;&#64;&#115;&#x74;&#114;&#111;&#98;&#101;&#x6c;&#x74;&#111;&#98;&#x69;&#x61;&#115;&#x2e;&#x64;&#101;">&#x67;&#x69;&#x74;&#64;&#115;&#x74;&#114;&#111;&#98;&#101;&#x6c;&#x74;&#111;&#98;&#x69;&#x61;&#115;&#x2e;&#x64;&#101;</a></td>
<td>91%</td>
</tr>
<tr>
@ -453,14 +454,14 @@ $$
<td><img src="https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/ru.png" alt=""></td>
<td>Русский</td>
<td>ru_RU</td>
<td>Artyom Karlov <a href="&#109;&#97;&#105;&#108;&#x74;&#x6f;&#x3a;&#97;&#114;&#116;&#x79;&#x6f;&#109;&#46;&#107;&#97;&#x72;&#x6c;&#x6f;&#x76;&#x40;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#x6d;">&#97;&#114;&#116;&#x79;&#x6f;&#109;&#46;&#107;&#97;&#x72;&#x6c;&#x6f;&#x76;&#x40;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#x6d;</a></td>
<td>Artyom Karlov <a href="&#109;&#x61;&#105;&#x6c;&#116;&#111;&#x3a;&#x61;&#114;&#x74;&#121;&#111;&#x6d;&#46;&#107;&#97;&#114;&#x6c;&#111;&#x76;&#64;&#x67;&#x6d;&#x61;&#105;&#x6c;&#46;&#99;&#x6f;&#109;">&#x61;&#114;&#x74;&#121;&#111;&#x6d;&#46;&#107;&#97;&#114;&#x6c;&#111;&#x76;&#64;&#x67;&#x6d;&#x61;&#105;&#x6c;&#46;&#99;&#x6f;&#109;</a></td>
<td>94%</td>
</tr>
<tr>
<td><img src="https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/cn.png" alt=""></td>
<td>中文 (简体)</td>
<td>zh_CN</td>
<td>RCJacH <a href="&#x6d;&#x61;&#x69;&#x6c;&#116;&#x6f;&#58;&#82;&#x43;&#74;&#97;&#99;&#72;&#64;&#x6f;&#117;&#x74;&#x6c;&#111;&#x6f;&#107;&#46;&#99;&#111;&#x6d;">&#82;&#x43;&#74;&#97;&#99;&#72;&#64;&#x6f;&#117;&#x74;&#x6c;&#111;&#x6f;&#107;&#46;&#99;&#111;&#x6d;</a></td>
<td>RCJacH <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#x3a;&#x52;&#67;&#74;&#x61;&#x63;&#x48;&#x40;&#111;&#117;&#x74;&#x6c;&#x6f;&#x6f;&#x6b;&#x2e;&#x63;&#x6f;&#109;">&#x52;&#67;&#74;&#x61;&#x63;&#x48;&#x40;&#111;&#117;&#x74;&#x6c;&#x6f;&#x6f;&#x6b;&#x2e;&#x63;&#x6f;&#109;</a></td>
<td>75%</td>
</tr>
<tr>