import React, {useEffect, useState} from 'react'; import {View, Text, TouchableOpacity} from 'react-native'; import NavigationService from '../../services/NavigationService'; import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu'; import { COLOR_SCHEME, SIZE, br, ph, pv, opacity, FONT, WEIGHT, } from '../../common/common'; import Icon from 'react-native-vector-icons/Feather'; import {w, ToastEvent} from '../../utils/utils'; import {storage} from '../../../App'; import {Dialog} from '../Dialog'; import {AddTopicDialog} from '../AddTopicDialog'; export const NotebookItem = ({ item, index, hideMore = false, topic, isTopic = false, isMove = false, noteToMove = null, notebookID, refresh = () => {}, }) => { const [colors, setColors] = useState(COLOR_SCHEME); const [isVisible, setVisible] = useState(false); const [addTopic, setAddTopic] = useState(false); let setMenuRef = {}; let show = null; const deleteItem = async () => { if (isTopic) { await storage.deleteTopicFromNotebook(notebookID, item.title); ToastEvent.show('Topic moved to trash', 'success', 3000); } else { await storage.deleteNotebooks([item]); ToastEvent.show('Notebook moved to trash', 'success', 3000); } refresh(); setVisible(false); }; const navigate = () => { isTopic ? NavigationService.navigate('Notes', item) : NavigationService.navigate('Notebook', { notebook: item, note: noteToMove, title: hideMore ? 'Choose topic' : item.title, isMove: isMove ? true : false, hideMore: hideMore ? true : false, }); }; const onMenuHide = () => { if (show) { if (show === 'delete') { setVisible(true); show = null; } else if (show === 'topic') { setAddTopic(true); show = null; } } }; const hideMenu = () => { setMenuRef[index].hide(); }; const showMenu = () => { setMenuRef[index].show(); }; return ( setVisible(false)} /> setAddTopic(false)} /> {item.title} {isTopic ? null : ( {item.description} )} {isTopic ? null : ( {item.topics.slice(0, 4).map(topic => ( {topic.title} ))} )} {isTopic ? null : ( {new Date(item.dateCreated).toDateString().substring(4)} )} {hideMore ? null : ( (setMenuRef[index] = ref)} button={ }> { show = 'topic'; hideMenu(); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Edit {' '}Pin { hideMenu(); ToastEvent.show( 'Note added to favorites.', 'success', 3000, () => {}, 'Ok', ); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Favorite { show = 'delete'; hideMenu(); }} textStyle={{ color: colors.pri, fontFamily: WEIGHT.regular, fontSize: SIZE.sm, }}> {' '}Delete )} {hideMore && isTopic ? ( { storage.addNoteToTopic( notebookID, item.title, noteToMove.dateCreated, ); NavigationService.navigate('Home'); ToastEvent.show(`Note moved to ${item.title}`, 'success', 3000); }} style={{ borderWidth: 1, borderRadius: 5, width: '20%', paddingHorizontal: ph - 5, borderColor: colors.nav, paddingVertical: pv, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: colors.accent, }}> Move ) : null} ); };