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

Mobile: Fixes #9312: Fix settings save confirmation not shown when navigating to encryption/profile/log screens (#9313)

This commit is contained in:
Henry Heino 2023-11-15 05:31:36 -08:00 committed by GitHub
parent cf19dacbaf
commit 6a6c8c1d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,10 +115,7 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
};
private manageProfilesButtonPress_ = () => {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'ProfileSwitcher',
});
void NavService.go('ProfileSwitcher');
};
private fixSearchEngineIndexButtonPress_ = async () => {
@ -206,6 +203,42 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
return 0;
}
private hasUnsavedChanges() {
return this.state.changedSettingKeys.length > 0;
}
private promptSaveChanges(): Promise<void> {
return new Promise(resolve => {
if (this.hasUnsavedChanges()) {
const dialogTitle: string|null = null;
Alert.alert(
dialogTitle,
_('There are unsaved changes.'),
[{
text: _('Save changes'),
onPress: async () => {
await this.saveButton_press();
resolve();
},
},
{
text: _('Discard changes'),
onPress: () => resolve(),
}],
);
} else {
resolve();
}
});
}
private handleNavigateToNewScren = async (): Promise<boolean> => {
await this.promptSaveChanges();
// Continue navigation
return false;
};
private handleBackButtonPress = (): boolean => {
const goBack = async () => {
BackButtonService.removeHandler(this.handleBackButtonPress);
@ -218,24 +251,11 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
return true;
}
if (this.state.changedSettingKeys.length > 0) {
const dialogTitle: string|null = null;
Alert.alert(
dialogTitle,
_('There are unsaved changes.'),
[{
text: _('Save changes'),
onPress: async () => {
await this.saveButton_press();
await goBack();
},
},
{
text: _('Discard changes'),
onPress: goBack,
}],
);
if (this.hasUnsavedChanges()) {
void (async () => {
await this.promptSaveChanges();
await goBack();
})();
return true;
}
@ -255,12 +275,14 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
}
BackButtonService.addHandler(this.handleBackButtonPress);
NavService.addHandler(this.handleNavigateToNewScren);
Dimensions.addEventListener('change', this.updateSidebarWidth);
this.updateSidebarWidth();
}
public componentWillUnmount() {
BackButtonService.removeHandler(this.handleBackButtonPress);
NavService.removeHandler(this.handleNavigateToNewScren);
}
private renderButton(key: string, title: string, clickHandler: ()=> void, options: any = null) {
@ -600,7 +622,7 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
showSaveButton={true}
showSearchButton={false}
showSideMenuButton={false}
saveButtonDisabled={!this.state.changedSettingKeys.length}
saveButtonDisabled={!this.hasUnsavedChanges()}
onSaveButtonPress={this.saveButton_press}
/>
{mainComponent}