import React, {useEffect} from 'react'; import {TouchableOpacity, View} from 'react-native'; import Animated, {Easing, useValue} from 'react-native-reanimated'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {useTracked} from '../../provider'; import {Actions} from '../../provider/Actions'; import {eSendEvent, ToastEvent} from '../../services/EventManager'; import {db} from '../../utils/DB'; import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events'; import {SIZE} from '../../utils/SizeUtils'; import {sleep} from '../../utils/TimeUtils'; import {ActionIcon} from '../ActionIcon'; import {TEMPLATE_DELETE} from '../DialogManager/Templates'; import Heading from '../Typography/Heading'; export const SelectionHeader = () => { // State const [state, dispatch] = useTracked(); const { colors, selectionMode, selectedItemsList, currentScreen, premiumUser, } = state; const insets = useSafeAreaInsets(); const translateY = useValue(-150); useEffect(() => { Animated.timing(translateY, { duration: 300, toValue: selectionMode ? 0 : -150, easing: Easing.in(Easing.ease), }).start(); }, [selectionMode]); return ( { dispatch({type: Actions.SELECTION_MODE, enabled: !selectionMode}); dispatch({type: Actions.CLEAR_SELECTION}); }} color={colors.heading} name="arrow-left" size={SIZE.xxxl} /> {Platform.OS === 'android' ? ( {selectedItemsList.length + ' Selected'} ) : null} {Platform.OS !== 'android' ? ( {selectedItemsList.length + ' Selected'} ) : null} {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( { dispatch({type: Actions.SELECTION_MODE, enabled: false}); await sleep(100); eSendEvent(eOpenMoveNoteDialog); }} customStyle={{ marginLeft: 10, }} color={colors.heading} name="plus" size={SIZE.xl} /> )} {currentScreen === 'trash' ? null : ( { eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item')); return; }} color={colors.heading} name="delete" size={SIZE.xl} /> )} {currentScreen === 'trash' ? ( { if (selectedItemsList.length > 0) { let noteIds = []; selectedItemsList.forEach((item) => { noteIds.push(item.id); }); await db.trash.restore(...noteIds); dispatch({type: Actions.NOTEBOOKS}); dispatch({type: Actions.NOTES}); dispatch({type: Actions.TRASH}); dispatch({type: Actions.SELECTION_MODE, enabled: false}); dispatch({type: Actions.CLEAR_SELECTION}); ToastEvent.show('Restore complete', 'success'); } }} name="delete-restore" size={SIZE.xl - 3} /> ) : null} ); }; export default SelectionHeader;