From 17fd8ee504db196176deac69ae685c685c575169 Mon Sep 17 00:00:00 2001 From: roman-r-m Date: Wed, 13 May 2020 11:39:16 +0100 Subject: [PATCH] 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. --- .../lib/components/select-date-time-dialog.js | 2 +- ReactNativeClient/setUpQuickActions.ts | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ReactNativeClient/lib/components/select-date-time-dialog.js b/ReactNativeClient/lib/components/select-date-time-dialog.js index 1cf6380c9f..22538db24d 100644 --- a/ReactNativeClient/lib/components/select-date-time-dialog.js +++ b/ReactNativeClient/lib/components/select-date-time-dialog.js @@ -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); } } diff --git a/ReactNativeClient/setUpQuickActions.ts b/ReactNativeClient/setUpQuickActions.ts index c8aed0e192..cf37dc311d 100644 --- a/ReactNativeClient/setUpQuickActions.ts +++ b/ReactNativeClient/setUpQuickActions.ts @@ -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)); }; +