import React, {useState, useRef} from 'react'; import { View, Text, TouchableOpacity, Dimensions, ScrollView, TextInput, FlatList, Modal, } from 'react-native'; import { COLOR_SCHEME, SIZE, br, ph, pv, WEIGHT, opacity, } 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'; import ActionSheet from '../ActionSheet'; import {ActionSheetComponent} from '../ActionSheetComponent'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; const NoteItem = props => { const {colors, updateDB} = useAppContext(); const [visible, setVisible] = useState(false); const [vaultDialog, setVaultDialog] = useState(false); const [unlock, setUnlock] = useState(false); const [isPerm, setIsPerm] = useState(false); const item = props.item; let actionSheet; let show = null; let setMenuRef = {}; let willRefresh = false; const onMenuHide = () => { if (show) { if (show === 'delete') { setVisible(true); show = null; } else if (show == 'lock') { setVaultDialog(true); show = null; } else if (show == 'unlock') { setUnlock(true); setIsPerm(true); 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); updateDB(); }; return ( { setVisible(false); }} /> { setVaultDialog(false); setUnlock(false); setIsPerm(false); updateDB(); }} note={item} perm={isPerm} openedToUnlock={unlock} visible={vaultDialog} /> {props.pinned ? ( ) : null} props.onLongPress()} onPress={() => { if (item.locked) { setUnlock(true); setVaultDialog(true); } else { NavigationService.navigate('Editor', { note: item, }); } }} style={{ paddingLeft: 0, width: '95%', }}> <> {item.title.replace('\n', '')} {item.headline[item.headline.length - 1] === '\n' ? item.headline.slice(0, item.headline.length - 1) : item.headline} {!props.isTrash ? ( <> {item.colors.length > 0 ? ( {item.colors.map(item => ( ))} ) : null} {item.locked ? ( ) : null} {item.favorite ? ( ) : null} {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} { actionSheet._setModalVisible(); }}> (actionSheet = ref)} customStyles={{ backgroundColor: colors.bg, }} indicatorColor={colors.shade} onClose={() => { onMenuHide(); if (willRefresh) { updateDB(); } }}> { willRefresh = true; }} hasColors={true} hasTags={true} overlayColor={ colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)' } rowItems={['Add to', 'Share', 'Export', 'Delete']} columnItems={['Add to Vault', 'Pin', 'Favorite']} close={value => { if (value) { show = value; } actionSheet._setModalVisible(); }} /> ); }; export default NoteItem;