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

Mobile: Fixes #2685: Fix quick actions (#2796)

* Fix quick actions

* Receive quick actions when the app is cold-launched

* Force side menu close before creating quick note

* Fix react warning: Can't perform a react state update on an unmounted component

The warning was:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in NoteScreenComponent (created by Connect(NoteScreenComponent))
    in Connect(NoteScreenComponent) (at app-nav.js:74)

* Fix auto title generation for quick notes.

The previous version created a new provisional note but then while handling NAV_BACK at reduxSharedMiddleware:35 the list of provisional note ids was cleared so when NoteScreenComponent was being mounted later the note was no longer considered provisional and Joplin would not generate the note title from its contents.

* Check for quick action data to be present before processing.

For some reason sometimes it gets called with null.
This commit is contained in:
roman-r-m 2020-05-13 11:39:16 +01:00 committed by GitHub
parent 05adb06aeb
commit 17fd8ee504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View File

@ -22,7 +22,7 @@ class SelectDateTimeDialog extends React.PureComponent {
this.setState({ date: newProps.date });
}
if ('shown' in newProps) {
if ('shown' in newProps && newProps.shown != this.shown_) {
this.show(newProps.shown);
}
}

View File

@ -4,6 +4,8 @@
const { DeviceEventEmitter } = require('react-native');
import * as QuickActions from 'react-native-quick-actions';
const { _ } = require('lib/locale.js');
const Note = require('lib/models/Note.js');
const { reg } = require('lib/registry.js');
type TData = {
type: string
@ -16,7 +18,9 @@ export default (dispatch: Function, folderId: string) => {
{ type: 'New to-do', title: _('New to-do'), icon: 'Add', userInfo },
]);
DeviceEventEmitter.addListener('quickActionShortcut', (data: TData) => {
const handleQuickAction = (data: TData) => {
if (!data) return;
// This dispatch is to momentarily go back to reset state, similar to what
// happens in onJoplinLinkClick_(). Easier to just go back, then go to the
// note since the Note screen doesn't handle reloading a different note.
@ -28,25 +32,25 @@ export default (dispatch: Function, folderId: string) => {
// note. If you navigate around enough (which I think changes the redux
// state sufficiently or something), then it'll work again.
dispatch({ type: 'NAV_BACK' });
dispatch({ type: 'SIDE_MENU_CLOSE' });
if (data.type === 'New note') {
const isTodo = data.type === 'New to-do' ? 1 : 0;
Note.save({
parent_id: folderId,
is_todo: isTodo,
}, { provisional: true }).then((newNote: any) => {
dispatch({
type: 'NAV_GO',
noteId: null,
noteId: newNote.id,
folderId,
routeName: 'Note',
itemType: 'note',
});
}
});
};
if (data.type === 'New to-do') {
dispatch({
type: 'NAV_GO',
noteId: null,
folderId,
routeName: 'Note',
itemType: 'todo',
});
}
});
DeviceEventEmitter.addListener('quickActionShortcut', handleQuickAction);
QuickActions.popInitialAction().then(handleQuickAction).catch((reason: any) => reg.logger().error(reason));
};