import React, {useEffect, useState} from 'react'; import {Text, 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 {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events'; import {TEMPLATE_DELETE} from '../DialogManager/Templates'; import {SIZE, WEIGHT} from "../../utils/SizeUtils"; import {db} from "../../utils/DB"; export const SelectionHeader = () => { // State const [state, dispatch] = useTracked(); const { colors, selectionMode, selectedItemsList, currentScreen, premiumUser, } = state; const [selectAll, setSelectAll] = useState(false); 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}); }} hitSlop={{top: 20, bottom: 20, left: 50, right: 40}} style={{ justifyContent: 'center', alignItems: 'flex-start', height: 40, width: 60, }}> {selectAll ? 'All' : selectedItemsList.length} {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( { dispatch({type: Actions.SELECTION_MODE, enabled: false}); dispatch({type: Actions.CLEAR_SELECTION}); eSendEvent(eOpenMoveNoteDialog); }}> )} {/* {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( { if (!premiumUser) { eSendEvent(eOpenPremiumDialog); return; } let favCount = 0; let unFavCount = 0; if (selectedItemsList.length > 0) { selectedItemsList.forEach(async (item) => { if (!item.favorite) { favCount += 1; } else { return; } await db.notes.note(item.id).favorite(); dispatch({type: ACTIONS.NOTES}); dispatch({type: ACTIONS.FAVORITES}); }); dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); dispatch({type: ACTIONS.CLEAR_SELECTION}); ToastEvent.show( favCount + ' notes added to favorites', 'success', ); } }}> )} */} {currentScreen === 'trash' ? null : ( { eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item')); return; }}> )} {currentScreen === 'trash' ? ( { if (selectedItemsList.length > 0) { let noteIds = []; selectedItemsList.forEach((item) => { noteIds.push(item.id); }); await db.trash.restore(...noteIds); dispatch({type: Actions.TRASH}); dispatch({type: Actions.SELECTION_MODE, enabled: false}); dispatch({type: Actions.CLEAR_SELECTION}); ToastEvent.show('Restore complete', 'success'); } }}> ) : null} {/* { if (selectAll) { dispatch({type: ACTIONS.SELECT_ALL, selected: []}); } else { dispatch({ type: ACTIONS.SELECT_ALL, selected: selection.type === 'notes' ? db.notes.all : selection.data, }); } setSelectAll(!selectAll); }} hitSlop={{top: 20, bottom: 20, left: 20, right: 40}} style={{ justifyContent: 'center', alignItems: 'center', height: 40, flexDirection: 'row', alignSelf: 'flex-start', marginLeft:5, marginBottom:5 }}> Select All */} ); }; export default SelectionHeader;