import React from 'react'; import {Text, TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; import {ACTIONS} from '../../provider/actions'; import NavigationService from '../../services/NavigationService'; import {db, ToastEvent} from '../../utils/utils'; import {ActionSheetEvent, moveNoteHideEvent} from '../DialogManager/recievers'; export const NotebookItem = ({ item, index, hideMore = false, topic, isTopic = false, isMove = false, noteToMove = null, notebookID, numColumns, isTrash, customStyle, onLongPress, navigation, selectionMode, pinned, }) => { const [state, dispatch] = useTracked(); const {colors, selectedItemsList} = state; const navigate = () => { if (selectionMode) { onLongPress(); return; } if (isTopic) { NavigationService.navigate('Notes', { ...item, }); } else { dispatch({ type: ACTIONS.HEADER_TEXT_STATE, state: { heading: hideMore ? 'Move to topic' : item.title, }, }); dispatch({ type: ACTIONS.HEADER_STATE, state: { canGoBack:true, menu:false }, }); dispatch({ type: ACTIONS.CONTAINER_BOTTOM_BUTTON, state: { bottomButtonText: 'Add new topic', }, }); hideMore ? navigation.navigate('Notebook', { notebook: item, title: hideMore ? 'Move to topic' : item.title, isMove: isMove, hideMore: hideMore, root:false }) : NavigationService.navigate('Notebook', { notebook: item, title: hideMore ? 'Select a topic' : item.title, isMove: isMove, hideMore: hideMore, root:true }); } }; return ( {item.title} {isTopic || !item.description ? null : ( {item.description} )} {isTopic ? null : ( {item && item.topics ? item.topics.slice(1, 4).map(topic => ( {topic.title} )) : null} )} {isTrash ? ( {'Deleted on: ' + item && item.dateDeleted ? new Date(item.dateDeleted).toISOString().slice(0, 10) : null + ' '} {item.type[0].toUpperCase() + item.type.slice(1) + ' '} ) : null} {item && item.totalNotes && item.totalNotes > 1 ? item.totalNotes + ' notes' : item.totalNotes === 1 ? item.totalNotes + ' note' : '0 notes'} {isTopic || isTrash ? null : ( {new Date(item.dateCreated).toDateString().substring(4)} )} {hideMore || (item.title === 'General' && item.type === 'topic') ? null : ( { let rowItems = isTrash ? ['Restore', 'Remove'] : [ item.type == 'topic' ? 'Edit Topic' : 'Edit Notebook', 'Delete', ]; let columnItems = item.type === 'topic' ? [] : ['Pin']; ActionSheetEvent(item, false, false, rowItems, columnItems, { notebookID: notebookID, }); }}> )} {hideMore && isTopic ? ( { let noteIds = []; selectedItemsList.forEach(item => noteIds.push(item.id)); await db.notes.move( { topic: item.title, id: item.notebookId, }, ...noteIds, ); dispatch({type: ACTIONS.CLEAR_SELECTION}); moveNoteHideEvent(); ToastEvent.show(`Note moved to ${item.title}`, 'success'); }} style={{ borderWidth: 1, borderRadius: 5, width: '20%', paddingHorizontal: ph - 5, borderColor: colors.nav, paddingVertical: pv - 5, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: colors.accent, }}> Move ) : null} ); };