import React, {useEffect} from 'react'; import { Platform, SafeAreaView, StatusBar, Text, TouchableOpacity, View, } from 'react-native'; import * as Animatable from 'react-native-animatable'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; import {ACTIONS} from '../../provider/actions'; import {w, ToastEvent, db} from '../../utils/utils'; import {eSendEvent} from '../../services/eventManager'; import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../services/events'; import {TEMPLATE_DELETE} from '../DialogManager'; export const AnimatedSafeAreaView = Animatable.createAnimatableComponent( SafeAreaView, ); export const SelectionHeader = ({navigation}) => { // State const [state, dispatch] = useTracked(); const {colors, selectionMode, selectedItemsList, currentScreen} = state; useEffect(() => { console.log(currentScreen); }, [currentScreen]); 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: 50, }}> {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 : ( { let favCount = 0; let unFavCount = 0; if (selectedItemsList.length > 0) { selectedItemsList.forEach(async item => { if (item.favorite) { favCount += 1; } else { unFavCount += 1; } 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 &' + unFavCount + 'removed', 'success', ); } }}> )} {currentScreen === 'trash' ? null : ( { eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item')); return; if (selectedItemsList.length > 0) { let noteIds = []; selectedItemsList.forEach(item => { noteIds.push(item.id); }); if (currentScreen === 'notebooks') { await db.notebooks.delete(...noteIds); dispatch({type: ACTIONS.NOTEBOOKS}); ToastEvent.show('Notebooks moved to trash'); } else if (currentScreen === 'notebook') { ToastEvent.show('Topics moved to trash'); // TODO } else { await db.notes.delete(...noteIds); dispatch({type: ACTIONS.NOTES}); ToastEvent.show('Notes moved to trash'); } dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); dispatch({type: ACTIONS.CLEAR_SELECTION}); } }}> )} {currentScreen === 'trash' ? ( { if (selectedItemsList.length > 0) { let noteIds = []; selectedItemsList.forEach(item => { noteIds.push(item.id); }); await db.trash.restore(...noteIds); console.log(noteIds); dispatch({type: ACTIONS.TRASH}); dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); dispatch({type: ACTIONS.CLEAR_SELECTION}); ToastEvent.show('Restore complete', 'success'); } }}> ) : null} ); }; export default SelectionHeader;