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

Mobile: Fixes #244: When accessing configuration or encrypt configuration option while making a note and the going back, the note gets erased

This commit is contained in:
Laurent Cozic 2018-02-21 22:08:34 +00:00
parent 14a93a9f26
commit 71aa841265
4 changed files with 59 additions and 25 deletions

View File

@ -4,6 +4,7 @@ const { Platform, View, Text, Button, StyleSheet, TouchableOpacity, Image, Scrol
const Icon = require('react-native-vector-icons/Ionicons').default;
const { Log } = require('lib/log.js');
const { BackButtonService } = require('lib/services/back-button.js');
const NavService = require('lib/services/NavService.js');
const { ReportService } = require('lib/services/report.js');
const { Menu, MenuOptions, MenuOption, MenuTrigger } = require('react-native-popup-menu');
const { _ } = require('lib/locale.js');
@ -160,10 +161,7 @@ class ScreenHeaderComponent extends Component {
}
searchButton_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Search',
});
NavService.go('Search');
}
async deleteButton_press() {
@ -184,38 +182,23 @@ class ScreenHeaderComponent extends Component {
}
log_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Log',
});
NavService.go('Log');
}
status_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Status',
});
NavService.go('Status');
}
config_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Config',
});
NavService.go('Config');
}
encryptionConfig_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'EncryptionConfig',
});
NavService.go('EncryptionConfig');
}
warningBox_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'EncryptionConfig',
});
NavService.go('EncryptionConfig');
}
async debugReport_press() {

View File

@ -9,6 +9,7 @@ const Setting = require('lib/models/Setting.js');
const Resource = require('lib/models/Resource.js');
const Folder = require('lib/models/Folder.js');
const { BackButtonService } = require('lib/services/back-button.js');
const NavService = require('lib/services/NavService.js');
const BaseModel = require('lib/BaseModel.js');
const { ActionButton } = require('lib/components/action-button.js');
const Icon = require('react-native-vector-icons/Ionicons').default;
@ -61,7 +62,7 @@ class NoteScreenComponent extends BaseScreenComponent {
this.styles_ = {};
this.backHandler = async () => {
const saveDialog = async () => {
if (this.isModified()) {
let buttonId = await dialogs.pop(this, _('This note has been modified:'), [
{ title: _('Save changes'), id: 'save' },
@ -73,6 +74,17 @@ class NoteScreenComponent extends BaseScreenComponent {
if (buttonId == 'save') await this.saveNoteButton_press();
}
return false;
}
this.navHandler = async () => {
return await saveDialog();
}
this.backHandler = async () => {
const r = await saveDialog();
if (r) return r;
if (!this.state.note.id) {
return false;
}
@ -145,6 +157,7 @@ class NoteScreenComponent extends BaseScreenComponent {
async componentWillMount() {
BackButtonService.addHandler(this.backHandler);
NavService.addHandler(this.navHandler);
await shared.initState(this);
@ -157,6 +170,7 @@ class NoteScreenComponent extends BaseScreenComponent {
componentWillUnmount() {
BackButtonService.removeHandler(this.backHandler);
NavService.removeHandler(this.navHandler);
}
title_changeText(text) {

View File

@ -0,0 +1,35 @@
class NavService {
static async go(routeName) {
if (this.handlers_.length) {
let r = await this.handlers_[this.handlers_.length - 1]();
if (r) return r;
}
this.dispatch({
type: 'NAV_GO',
routeName: routeName,
});
}
static addHandler(handler) {
for (let i = this.handlers_.length - 1; i >= 0; i--) {
const h = this.handlers_[i];
if (h === handler) return;
}
return this.handlers_.push(handler);
}
static removeHandler(hanlder) {
for (let i = this.handlers_.length - 1; i >= 0; i--) {
const h = this.handlers_[i];
if (h === hanlder) this.handlers_.splice(i, 1);
}
}
}
NavService.handlers_ = [];
module.exports = NavService;

View File

@ -3,6 +3,7 @@ const { AppState, Keyboard, NativeModules, BackHandler } = require('react-native
const { SafeAreaView } = require('react-navigation');
const { connect, Provider } = require('react-redux');
const { BackButtonService } = require('lib/services/back-button.js');
const NavService = require('lib/services/NavService.js');
const AlarmService = require('lib/services/AlarmService.js');
const AlarmServiceDriver = require('lib/services/AlarmServiceDriver');
const Alarm = require('lib/models/Alarm');
@ -338,6 +339,7 @@ async function initialize(dispatch) {
BaseModel.dispatch = dispatch;
FoldersScreenUtils.dispatch = dispatch;
BaseSyncTarget.dispatch = dispatch;
NavService.dispatch = dispatch;
BaseModel.db_ = db;
BaseItem.loadClass('Note', Note);