import React, {useState} from 'react'; import {View, Text, TouchableOpacity, Dimensions} from 'react-native'; import {COLOR_SCHEME, SIZE, br, ph, pv, WEIGHT} from '../../common/common'; import Icon from 'react-native-vector-icons/Feather'; import { timeSince, ToastEvent, SideMenuEvent, getElevation, } from '../../utils/utils'; import NavigationService from '../../services/NavigationService'; import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu'; import {Dialog} from '../Dialog'; import {VaultDialog} from '../VaultDialog'; import {db} from '../../../App'; import {DDS} from '../../../App'; import {useAppContext} from '../../provider/useAppContext'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; const NoteItem = props => { const {colors} = useAppContext(); const [visible, setVisible] = useState(false); const [vaultDialog, setVaultDialog] = useState(false); const item = props.item; let show = null; let setMenuRef = {}; const onMenuHide = () => { if (show) { if (show === 'delete') { setVisible(true); show = null; } else if (show == 'vault') { setVaultDialog(true); show = null; } } }; const hideMenu = () => { setMenuRef[props.index].hide(); }; const showMenu = () => { setMenuRef[props.index].show(); }; const deleteItem = async () => { await db.deleteNotes([item]); ToastEvent.show('Note moved to trash', 'success', 3000); setVisible(false); props.refresh(); }; return ( { setVisible(false); }} /> {props.pinned ? ( ) : null} { SideMenuEvent.close(); SideMenuEvent.disable(); NavigationService.navigate('Editor', { note: item, }); }} style={{ paddingLeft: 0, width: '95%', }}> <> {item.title.replace('\n', '')} {item.headline} {!props.isTrash ? ( <> {timeSince(item.dateCreated) + ' '} ) : null} {props.isTrash ? ( <> {'Deleted on: ' + new Date(item.dateDeleted).toISOString().slice(0, 10) + ' '} {item.type[0].toUpperCase() + item.type.slice(1) + ' '} ) : null} (setMenuRef[props.index] = ref)} button={ }> {props.isTrash ? ( <> { show = 'topic'; hideMenu(); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Restore { show = 'topic'; hideMenu(); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Remove ) : ( <> {' '}Pin { hideMenu(); ToastEvent.show( 'Note added to favorites.', 'success', 3000, () => {}, 'Ok', ); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.xs, }}> {' '}Favorite {' '}Share { hideMenu(); NavigationService.push('Folders', { note: item, title: 'Choose Notebook', isMove: true, hideMore: true, }); }} style={{ height: 35, }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.xs, }}> {' '}Move { show = 'vault'; hideMenu(true); }} style={{ height: 35, }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.xs, }}> {' '}Lock { show = 'delete'; hideMenu(); }} style={{ height: 35, }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.xs, }}> {' '}Delete Notebook: School Notes {' '}- Topic: Physics Created on:{' '} {new Date(item.dateCreated).toISOString().slice(0, 10)} )} ); }; export default NoteItem;