import React, {useState, createRef} from 'react'; import { View, Text, TouchableOpacity, ScrollView, Dimensions, FlatList, TouchableWithoutFeedback, Platform, } from 'react-native'; import { COLOR_SCHEME, SIZE, br, ph, pv, opacity, FONT, WEIGHT, } from '../../common/common'; import Icon from 'react-native-vector-icons/Feather'; import {Reminder} from '../Reminder'; import {getElevation, timeSince, ToastEvent} 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 {storage} from '../../../App'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; const NoteItem = props => { const [colors, setColors] = useState(COLOR_SCHEME); 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 storage.deleteNotes([item]); ToastEvent.show('Note moved to trash', 'success', 3000); setVisible(false); props.refresh(); }; return ( { setVisible(false); }} /> { NavigationService.navigate('Editor', { note: item, }); }} style={{ paddingLeft: ph, width: '100%', }}> <> {item.title.replace('\n', '')} {item.headline} {timeSince(item.dateCreated) + ' '} (setMenuRef[props.index] = ref)} button={ }> {' '}Pin { hideMenu(); ToastEvent.show( 'Note added to favorites.', 'success', 3000, () => {}, 'Ok', ); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Favorite {' '}Share { hideMenu(); NavigationService.navigate('Folders', { note: item, title: 'Choose Notebook', isMove: true, hideMore: true, }); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Move { show = 'vault'; hideMenu(true); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Lock { show = 'delete'; hideMenu(); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Delete Notebook: School Notes {' '}- Topic: Physics Created on: {new Date(item.dateCreated).toISOString().slice(0, 10)} ); }; export default NoteItem;