2020-02-19 02:41:49 +02:00
|
|
|
// Need to require this class instead of importing it
|
|
|
|
// to disable buggy type-checking, maybe because this
|
|
|
|
// class is undocumented.
|
|
|
|
const { DeviceEventEmitter } = require('react-native');
|
2020-02-19 01:52:36 +02:00
|
|
|
import * as QuickActions from 'react-native-quick-actions';
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
|
|
|
|
type TData = {
|
|
|
|
type: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (dispatch: Function, folderId: string) => {
|
|
|
|
const userInfo = { url: '' };
|
|
|
|
QuickActions.setShortcutItems([
|
2020-02-19 02:09:19 +02:00
|
|
|
{ type: 'New note', title: _('New note'), icon: 'Compose', userInfo },
|
|
|
|
{ type: 'New to-do', title: _('New to-do'), icon: 'Add', userInfo },
|
2020-02-19 01:52:36 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
DeviceEventEmitter.addListener('quickActionShortcut', (data: TData) => {
|
|
|
|
// 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.
|
2020-02-19 02:09:19 +02:00
|
|
|
dispatch({ type: 'NAV_BACK' });
|
2020-02-19 01:52:36 +02:00
|
|
|
|
|
|
|
if (data.type === 'New note') {
|
|
|
|
dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
noteId: null,
|
|
|
|
folderId,
|
|
|
|
routeName: 'Note',
|
|
|
|
itemType: 'note',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.type === 'New to-do') {
|
|
|
|
dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
noteId: null,
|
|
|
|
folderId,
|
|
|
|
routeName: 'Note',
|
|
|
|
itemType: 'todo',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|