mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
All: Improved the way settings are changed. Should also fixed issue with sync context being accidentally broken.
This commit is contained in:
parent
ef0cc5e33e
commit
214a39c3d3
@ -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']);
|
||||
|
||||
|
@ -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/)
|
||||
|
||||
|
@ -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 >
|
||||
|
@ -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;
|
@ -310,6 +310,7 @@ sudo ln -s ~/.joplin-bin/bin/joplin /usr/bin/joplin
|
||||
<p>Select the "WebDAV" 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="mailto:trbuhom@net.hr">trbuhom@net.hr</a></td>
|
||||
<td>Hrvoje Mandić <a href="mailto:trbuhom@net.hr">trbuhom@net.hr</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="mailto:git@strobeltobias.de">git@strobeltobias.de</a></td>
|
||||
<td>Tobias Strobel <a href="mailto:git@strobeltobias.de">git@strobeltobias.de</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="mailto:artyom.karlov@gmail.com">artyom.karlov@gmail.com</a></td>
|
||||
<td>Artyom Karlov <a href="mailto:artyom.karlov@gmail.com">artyom.karlov@gmail.com</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="mailto:RCJacH@outlook.com">RCJacH@outlook.com</a></td>
|
||||
<td>RCJacH <a href="mailto:RCJacH@outlook.com">RCJacH@outlook.com</a></td>
|
||||
<td>75%</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
Loading…
Reference in New Issue
Block a user