Mobile: Added button to clear local sync state

pull/1680/head
Laurent Cozic 2019-06-19 14:57:59 +01:00
parent 349cade946
commit 6ce091f4d8
3 changed files with 50 additions and 3 deletions

View File

@ -19,5 +19,5 @@
# Required for react-native-webview # Required for react-native-webview
# https://github.com/react-native-community/react-native-webview/blob/master/docs/Getting-Started.md # https://github.com/react-native-community/react-native-webview/blob/master/docs/Getting-Started.md
# android.useAndroidX=true android.useAndroidX=true
# android.enableJetifier=true android.enableJetifier=true

View File

@ -1,5 +1,5 @@
const React = require('react'); const Component = React.Component; const React = require('react'); const Component = React.Component;
const { Platform, TouchableOpacity, Linking, View, Switch, StyleSheet, Text, Button, ScrollView, TextInput } = require('react-native'); const { Platform, TouchableOpacity, Linking, View, Switch, StyleSheet, Text, Button, ScrollView, TextInput, Alert } = require('react-native');
const { connect } = require('react-redux'); const { connect } = require('react-redux');
const { ScreenHeader } = require('lib/components/screen-header.js'); const { ScreenHeader } = require('lib/components/screen-header.js');
const { _, setLocale } = require('lib/locale.js'); const { _, setLocale } = require('lib/locale.js');
@ -7,6 +7,7 @@ const { BaseScreenComponent } = require('lib/components/base-screen.js');
const { Dropdown } = require('lib/components/Dropdown.js'); const { Dropdown } = require('lib/components/Dropdown.js');
const { themeStyle } = require('lib/components/global-style.js'); const { themeStyle } = require('lib/components/global-style.js');
const Setting = require('lib/models/Setting.js'); const Setting = require('lib/models/Setting.js');
const BaseItem = require('lib/models/BaseItem.js');
const shared = require('lib/components/shared/config-shared.js'); const shared = require('lib/components/shared/config-shared.js');
const SyncTargetRegistry = require('lib/SyncTargetRegistry'); const SyncTargetRegistry = require('lib/SyncTargetRegistry');
const { reg } = require('lib/registry.js'); const { reg } = require('lib/registry.js');
@ -33,6 +34,35 @@ class ConfigScreenComponent extends BaseScreenComponent {
this.saveButton_press = () => { this.saveButton_press = () => {
return shared.saveSettings(this); return shared.saveSettings(this);
}; };
this.clearSyncStateButton_click = () => {
Alert.alert(
'',
_('WARNING: This will clear the local synchronisation state. It means the entire data will be synced again with the sync target. DO NOT USE if you have not been advised to do so, or if you do not understand the consequences.'),
[
{
text: _('Help'),
onPress: () => {
Linking.openURL('https://joplinapp.org/faq/#how-to-clear-local-sync-data');
},
},
{
text: _('Cancel'),
onPress: () => {},
style: 'cancel',
},
{
text: _('OK'),
onPress: async () => {
const syncTarget = this.props.settings['sync.target'];
await BaseItem.clearLocalSyncState(syncTarget);
alert(_('The local sync data has been cleared.'));
},
},
],
{ cancelable: false },
);
};
} }
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
@ -273,6 +303,18 @@ class ConfigScreenComponent extends BaseScreenComponent {
const settingComps = shared.settingsToComponents2(this, 'mobile', settings); const settingComps = shared.settingsToComponents2(this, 'mobile', settings);
settingComps.push(this.renderHeader('advanced', _('Advanced')));
settingComps.push(
<View key="advanced_clear_sync_state" style={this.styles().settingContainer}>
<View style={{flex:1, flexDirection: 'column'}}>
<View style={{flex:1}}>
<Button title={_('Clear synchronisation state')} onPress={this.clearSyncStateButton_click}/>
</View>
</View>
</View>
);
settingComps.push(this.renderHeader('moreInfo', _('More information'))); settingComps.push(this.renderHeader('moreInfo', _('More information')));
if (Platform.OS === 'android' && Platform.Version >= 23) { if (Platform.OS === 'android' && Platform.Version >= 23) {

View File

@ -694,6 +694,11 @@ class BaseItem extends BaseModel {
} }
} }
static async clearLocalSyncState(syncTarget) {
await this.db().exec('DELETE FROM sync_items WHERE sync_target = ?', [syncTarget]);
await this.db().exec('DELETE FROM deleted_items WHERE sync_target = ?', [syncTarget]);
}
static async forceSync(itemId) { static async forceSync(itemId) {
await this.db().exec('UPDATE sync_items SET force_sync = 1 WHERE item_id = ?', [itemId]); await this.db().exec('UPDATE sync_items SET force_sync = 1 WHERE item_id = ?', [itemId]);
} }