mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-11 11:12:03 +02:00
This commit is contained in:
parent
5e592a3096
commit
75dfb0af5f
@ -982,7 +982,7 @@ class AppComponent extends React.Component {
|
||||
);
|
||||
onSystemColorSchemeChange(Appearance.getColorScheme());
|
||||
|
||||
setupQuickActions(this.props.dispatch, this.props.selectedFolderId);
|
||||
this.quickActionShortcutListener_ = await setupQuickActions(this.props.dispatch);
|
||||
|
||||
await setupNotifications(this.props.dispatch);
|
||||
|
||||
@ -1017,6 +1017,11 @@ class AppComponent extends React.Component {
|
||||
this.unsubscribeNewShareListener_();
|
||||
this.unsubscribeNewShareListener_ = undefined;
|
||||
}
|
||||
|
||||
if (this.quickActionShortcutListener_) {
|
||||
this.quickActionShortcutListener_.remove();
|
||||
this.quickActionShortcutListener_ = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
|
@ -1,59 +1,49 @@
|
||||
// Need to require this class instead of importing it
|
||||
// to disable buggy type-checking, maybe because this
|
||||
// class is undocumented.
|
||||
import * as QuickActions from 'react-native-quick-actions';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
const { DeviceEventEmitter } = require('react-native');
|
||||
import Note from '@joplin/lib/models/Note';
|
||||
import { reg } from '@joplin/lib/registry';
|
||||
import { Dispatch } from 'redux';
|
||||
import CommandService from '@joplin/lib/services/CommandService';
|
||||
import Logger from '@joplin/utils/Logger';
|
||||
import { DeviceEventEmitter } from 'react-native';
|
||||
|
||||
const logger = Logger.create('setupQuickActions');
|
||||
|
||||
type TData = {
|
||||
type: string;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
||||
export default (dispatch: Function, folderId: string) => {
|
||||
export default async (dispatch: Dispatch) => {
|
||||
const userInfo = { url: '' };
|
||||
QuickActions.setShortcutItems([
|
||||
{ type: 'New note', title: _('New note'), icon: 'Compose', userInfo },
|
||||
{ type: 'New to-do', title: _('New to-do'), icon: 'Add', userInfo },
|
||||
]);
|
||||
|
||||
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.
|
||||
//
|
||||
// This hack is necessary because otherwise you get this problem:
|
||||
// The first time you create a note from the quick-action menu, it works
|
||||
// perfectly. But if you do it again immediately later, it re-opens the
|
||||
// page to that first note you made rather than creating an entirely new
|
||||
// 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' });
|
||||
|
||||
const isTodo = data.type === 'New to-do' ? 1 : 0;
|
||||
|
||||
void Note.save({
|
||||
parent_id: folderId,
|
||||
is_todo: isTodo,
|
||||
// eslint-disable-next-line promise/prefer-await-to-then, @typescript-eslint/no-explicit-any -- Old code before rule was applied, Old code before rule was applied
|
||||
}, { provisional: true }).then((newNote: any) => {
|
||||
dispatch({
|
||||
type: 'NAV_GO',
|
||||
noteId: newNote.id,
|
||||
folderId,
|
||||
routeName: 'Note',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
DeviceEventEmitter.addListener('quickActionShortcut', handleQuickAction);
|
||||
|
||||
// eslint-disable-next-line promise/prefer-await-to-then, @typescript-eslint/no-explicit-any -- Old code before rule was applied, Old code before rule was applied
|
||||
QuickActions.popInitialAction().then(handleQuickAction).catch((reason: any) => reg.logger().error(reason));
|
||||
try {
|
||||
const data = await QuickActions.popInitialAction();
|
||||
const handler = quickActionHandler(dispatch);
|
||||
await handler(data);
|
||||
} catch (error) {
|
||||
logger.error('Quick action command failed', error);
|
||||
}
|
||||
return DeviceEventEmitter.addListener('quickActionShortcut', quickActionHandler(dispatch));
|
||||
};
|
||||
|
||||
const quickActionHandler = (dispatch: Dispatch) => async (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.
|
||||
//
|
||||
// This hack is necessary because otherwise you get this problem:
|
||||
// The first time you create a note from the quick-action menu, it works
|
||||
// perfectly. But if you do it again immediately later, it re-opens the
|
||||
// page to that first note you made rather than creating an entirely new
|
||||
// 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' });
|
||||
|
||||
const isTodo = data.type === 'New to-do' ? 1 : 0;
|
||||
await CommandService.instance().execute('newNote', '', isTodo);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user