import React, {useState, useEffect} from 'react'; import {Platform, StatusBar, Text, TouchableOpacity, View} from 'react-native'; import * as Animatable from 'react-native-animatable'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; import {ACTIONS} from '../../provider/actions'; import {eSendEvent} from '../../services/eventManager'; import { eOpenMoveNoteDialog, eOpenPremiumDialog, eOpenSimpleDialog, } from '../../services/events'; import {db, ToastEvent} from '../../utils/utils'; import {TEMPLATE_DELETE} from '../DialogManager/templates'; import Animated, {useValue, Easing} from 'react-native-reanimated'; export const SelectionHeader = () => { // State const [state, dispatch] = useTracked(); const { colors, selectionMode, selectedItemsList, currentScreen, containerState, 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 containerState.noSelectionHeader ? null : ( { 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;