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' ; type TData = { type : string ; } ; export default ( dispatch , folderId ) => { 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 ) => { if ( ! data ) return ; 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 , } , { provisional : true } ) . then ( ( newNote ) => { dispatch ( { type : 'NAV_GO' , noteId : newNote . id , folderId , routeName : 'Note' , } ) ; } ) ; } ; DeviceEventEmitter . addListener ( 'quickActionShortcut' , handleQuickAction ) ; QuickActions . popInitialAction ( ) . then ( handleQuickAction ) . catch ( ( reason ) => reg . logger ( ) . error ( reason ) ) ; } ;