import React from 'react'; import {Dimensions, Text, View, TouchableOpacity} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {ActionIcon} from '../ActionIcon'; import {ActionSheetEvent, updateEvent} from '../DialogManager/recievers'; import {timeSince} from '../../utils/TimeUtils'; import {ph, SIZE, WEIGHT} from '../../utils/SizeUtils'; import Paragraph from '../Typography/Paragraph'; import Heading from '../Typography/Heading'; import {db} from '../../utils/DB'; import {Actions} from '../../provider/Actions'; import NavigationService from '../../services/Navigation'; import {COLORS_NOTE} from '../../utils/Colors'; export default class NoteItem extends React.Component { constructor(props) { super(props); this.cipher = { value: false, }; this.colors = []; this.actionSheet; this.show = null; this.setMenuRef = {}; this.willRefresh = false; } shouldComponentUpdate(nextProps, nextState) { if ( nextProps.item.locked !== this.cipher.value || nextProps.item.colors.length !== this.colors.length || nextProps.selectionMode !== this.props.selectionMode ) { return true; } else { return ( JSON.stringify(nextProps) !== JSON.stringify(this.props) || nextState !== this.state ); } } componentDidUpdate() { this.colors = [...this.props.item.colors]; this.cipher.value = this.props.item.locked ? true : false; } componentWillUnmount() { this.colors = []; this.cipher.value = false; } componentDidMount() { this.colors = []; if (this.props.item.locked) { this.cipher.value = true; } } render() { let {colors, item, customStyle, isTrash} = this.props; return ( {item.notebook && item.notebook.id && ( { let notebook = db.notebooks.notebook(item.notebook.id).data; updateEvent({ type: Actions.HEADER_TEXT_STATE, state: { heading: notebook.title, }, }); updateEvent({ type: Actions.HEADER_STATE, state: false, }); NavigationService.navigate('Notebook', { notebook: db.notebooks.notebook(item.notebook.id).data, title: notebook.title, root: true, }); }} style={{ paddingVertical: 1.5, marginBottom: 2.5, }}> {db.notebooks.notebook(item.notebook.id).title} )} {item.title.replace('\n', '')} {item.headline[item.headline.length - 1] === '\n' ? item.headline.slice(0, item.headline.length - 1) : item.headline} {!isTrash ? ( <> {item.colors.length > 0 ? ( {item.colors.map((item) => ( ))} ) : null} {item.locked ? ( ) : null} {item.favorite ? ( ) : null} {timeSince(item.dateCreated)} ) : null} {isTrash ? ( <> {item.itemType[0].toUpperCase() + item.itemType.slice(1) + ' '} Deleted on{' '} {item && item.dateDeleted ? new Date(item.dateDeleted).toISOString().slice(0, 10) : null + ' '} ) : null} {item.conflicted ? ( CONFLICTS ) : null} { ActionSheetEvent( item, isTrash ? false : true, isTrash ? false : true, isTrash ? ['Remove', 'Restore'] : ['Add to', 'Share', 'Export', 'Delete', 'Copy'], isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'], ); }} customStyle={{ justifyContent: 'center', height: 35, width: 35, borderRadius: 100, alignItems: 'center', }} /> ); } }