2020-01-16 19:55:52 +05:00
|
|
|
import React from 'react';
|
2020-02-06 13:08:35 +05:00
|
|
|
import {Dimensions, Text, TouchableOpacity, View} from 'react-native';
|
2019-12-04 19:38:19 +05:00
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2019-12-14 16:00:16 +05:00
|
|
|
import {DDS} from '../../../App';
|
2020-01-18 01:04:33 +05:00
|
|
|
import {ph, pv, SIZE, WEIGHT} from '../../common/common';
|
2020-02-06 13:08:35 +05:00
|
|
|
import {eSendEvent} from '../../services/eventManager';
|
|
|
|
|
import {eOnLoadNote} from '../../services/events';
|
2020-01-18 01:04:33 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
|
|
|
|
import {getElevation, timeSince} from '../../utils/utils';
|
2020-02-02 16:18:52 +05:00
|
|
|
import {
|
|
|
|
|
ActionSheetEvent,
|
|
|
|
|
simpleDialogEvent,
|
2020-02-06 13:08:35 +05:00
|
|
|
TEMPLATE_TRASH,
|
2020-02-02 16:18:52 +05:00
|
|
|
} from '../DialogManager';
|
2020-01-17 10:58:12 +05:00
|
|
|
|
2019-11-17 16:02:19 +05:00
|
|
|
const w = Dimensions.get('window').width;
|
|
|
|
|
const h = Dimensions.get('window').height;
|
2019-12-05 17:40:09 +05:00
|
|
|
|
2020-01-16 19:55:52 +05:00
|
|
|
export default class NoteItem extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2020-01-17 21:05:53 +05:00
|
|
|
this.cipher = {
|
|
|
|
|
value: false,
|
|
|
|
|
};
|
2020-01-16 19:55:52 +05:00
|
|
|
this.actionSheet;
|
|
|
|
|
this.show = null;
|
|
|
|
|
this.setMenuRef = {};
|
|
|
|
|
this.willRefresh = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2020-01-17 21:05:53 +05:00
|
|
|
if (nextProps.item.locked !== this.cipher.value) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
JSON.stringify(nextProps) !== JSON.stringify(this.props) ||
|
|
|
|
|
nextState !== this.state
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
|
this.cipher.value = this.props.item.locked ? true : false;
|
|
|
|
|
}
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
this.cipher.value = false;
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
if (this.props.item.locked) {
|
|
|
|
|
this.cipher.value = true;
|
|
|
|
|
}
|
2020-01-16 19:55:52 +05:00
|
|
|
}
|
2019-12-09 13:17:40 +05:00
|
|
|
|
2020-01-16 19:55:52 +05:00
|
|
|
render() {
|
|
|
|
|
let {
|
|
|
|
|
colors,
|
|
|
|
|
item,
|
|
|
|
|
customStyle,
|
|
|
|
|
onLongPress,
|
|
|
|
|
isTrash,
|
|
|
|
|
pinned,
|
|
|
|
|
index,
|
|
|
|
|
} = this.props;
|
2020-02-06 13:08:35 +05:00
|
|
|
console.log('rerendering', index, item.content.text.length);
|
2020-01-16 19:55:52 +05:00
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={[
|
|
|
|
|
{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
justifyContent: 'flex-start',
|
2019-12-21 09:46:08 +05:00
|
|
|
alignItems: 'center',
|
2020-01-16 19:55:52 +05:00
|
|
|
flexDirection: 'row',
|
2020-01-22 02:51:24 +05:00
|
|
|
maxWidth: '100%',
|
2020-02-02 23:43:46 +05:00
|
|
|
paddingRight: 6,
|
2020-01-16 19:55:52 +05:00
|
|
|
alignSelf: 'center',
|
|
|
|
|
borderBottomWidth: 1,
|
2020-01-24 19:36:58 +05:00
|
|
|
borderBottomColor: colors.nav,
|
2020-01-16 19:55:52 +05:00
|
|
|
},
|
|
|
|
|
customStyle ? customStyle : {},
|
|
|
|
|
]}>
|
|
|
|
|
{pinned ? (
|
2019-11-28 21:40:37 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-01-16 19:55:52 +05:00
|
|
|
...getElevation(3),
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
left: 20,
|
|
|
|
|
top: -15,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-11-28 21:40:37 +05:00
|
|
|
}}>
|
2020-01-16 19:55:52 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: 5,
|
|
|
|
|
height: 5,
|
|
|
|
|
backgroundColor: 'white',
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
2020-02-02 20:44:17 +05:00
|
|
|
activeOpacity={0.8}
|
2020-01-16 19:55:52 +05:00
|
|
|
onLongPress={() => onLongPress()}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
if (item.locked) {
|
|
|
|
|
this.setState({
|
|
|
|
|
unlock: true,
|
|
|
|
|
vaultDialog: true,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2020-01-22 02:51:24 +05:00
|
|
|
DDS.isTab
|
2020-01-25 20:12:47 +05:00
|
|
|
? eSendEvent(eOnLoadNote, item)
|
2020-02-02 16:18:52 +05:00
|
|
|
: isTrash
|
|
|
|
|
? simpleDialogEvent(TEMPLATE_TRASH(item.type))
|
2020-01-22 02:51:24 +05:00
|
|
|
: NavigationService.navigate('Editor', {
|
|
|
|
|
note: item,
|
|
|
|
|
});
|
2020-01-16 19:55:52 +05:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingLeft: 0,
|
|
|
|
|
width: '95%',
|
|
|
|
|
}}>
|
|
|
|
|
<>
|
2019-11-28 21:40:37 +05:00
|
|
|
<Text
|
2020-01-16 19:55:52 +05:00
|
|
|
numberOfLines={1}
|
2019-11-28 21:40:37 +05:00
|
|
|
style={{
|
2020-01-24 19:36:58 +05:00
|
|
|
color: colors.pri,
|
2020-02-02 19:09:33 +05:00
|
|
|
fontSize: SIZE.sm + 1,
|
2020-01-16 19:55:52 +05:00
|
|
|
fontFamily: WEIGHT.bold,
|
2020-02-02 23:43:46 +05:00
|
|
|
maxWidth: '100%',
|
2019-11-28 21:40:37 +05:00
|
|
|
}}>
|
2020-01-16 19:55:52 +05:00
|
|
|
{item.title.replace('\n', '')}
|
2019-11-28 21:40:37 +05:00
|
|
|
</Text>
|
2019-12-06 12:06:03 +05:00
|
|
|
<View
|
2019-11-28 21:40:37 +05:00
|
|
|
style={{
|
2019-12-06 12:06:03 +05:00
|
|
|
justifyContent: 'flex-start',
|
2020-01-16 19:55:52 +05:00
|
|
|
alignItems: 'flex-start',
|
2020-01-06 19:03:21 +05:00
|
|
|
width: '100%',
|
2019-11-28 21:40:37 +05:00
|
|
|
}}>
|
2020-01-16 19:55:52 +05:00
|
|
|
<Text
|
2020-01-24 19:11:31 +05:00
|
|
|
numberOfLines={2}
|
2020-01-16 19:55:52 +05:00
|
|
|
style={{
|
2020-02-02 19:09:33 +05:00
|
|
|
fontSize: SIZE.sm - 1,
|
2020-01-24 19:11:31 +05:00
|
|
|
color: colors.pri + 'B3',
|
2020-01-16 19:55:52 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
width: '100%',
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
paddingRight: ph,
|
|
|
|
|
}}>
|
|
|
|
|
{item.headline[item.headline.length - 1] === '\n'
|
|
|
|
|
? item.headline.slice(0, item.headline.length - 1)
|
|
|
|
|
: item.headline}
|
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
width: '100%',
|
2020-02-02 23:05:14 +05:00
|
|
|
marginTop: 5,
|
2020-01-16 19:55:52 +05:00
|
|
|
}}>
|
|
|
|
|
{!isTrash ? (
|
|
|
|
|
<>
|
|
|
|
|
{item.colors.length > 0 ? (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 10,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
{item.colors.map(item => (
|
|
|
|
|
<View
|
|
|
|
|
key={item}
|
|
|
|
|
style={{
|
|
|
|
|
width: SIZE.xs,
|
|
|
|
|
height: SIZE.xs,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
backgroundColor: item,
|
|
|
|
|
marginRight: -4.5,
|
|
|
|
|
}}></View>
|
|
|
|
|
))}
|
|
|
|
|
</View>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{item.locked ? (
|
|
|
|
|
<Icon
|
|
|
|
|
style={{marginRight: 10}}
|
|
|
|
|
name="lock"
|
|
|
|
|
size={SIZE.xs}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{item.favorite ? (
|
|
|
|
|
<Icon
|
|
|
|
|
style={{marginRight: 10}}
|
|
|
|
|
name="star"
|
|
|
|
|
size={SIZE.xs + 1}
|
|
|
|
|
color="orange"
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<Text
|
2020-01-10 18:46:52 +05:00
|
|
|
style={{
|
2020-01-16 19:55:52 +05:00
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.xs - 1,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
2020-01-10 18:46:52 +05:00
|
|
|
marginRight: 10,
|
|
|
|
|
}}>
|
2020-01-16 19:55:52 +05:00
|
|
|
{timeSince(item.dateCreated)}
|
|
|
|
|
</Text>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
2019-12-06 12:06:03 +05:00
|
|
|
|
2020-01-16 19:55:52 +05:00
|
|
|
{isTrash ? (
|
|
|
|
|
<>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.xs - 1,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}>
|
|
|
|
|
{'Deleted on: ' +
|
|
|
|
|
new Date(item.dateDeleted).toISOString().slice(0, 10) +
|
|
|
|
|
' '}
|
|
|
|
|
</Text>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
|
|
|
|
fontSize: SIZE.xs - 1,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}>
|
|
|
|
|
{item.type[0].toUpperCase() + item.type.slice(1) + ' '}
|
|
|
|
|
</Text>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
</View>
|
2019-12-06 12:06:03 +05:00
|
|
|
</View>
|
2020-01-16 19:55:52 +05:00
|
|
|
</>
|
|
|
|
|
</TouchableOpacity>
|
2019-11-28 21:40:37 +05:00
|
|
|
|
2020-01-16 19:55:52 +05:00
|
|
|
<View
|
2020-01-09 19:48:39 +05:00
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-01-16 19:55:52 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
2020-01-11 23:06:29 +05:00
|
|
|
}}
|
2020-01-16 19:55:52 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
ActionSheetEvent(
|
|
|
|
|
item,
|
2020-02-02 16:18:52 +05:00
|
|
|
isTrash ? false : true,
|
|
|
|
|
isTrash ? false : true,
|
|
|
|
|
isTrash
|
|
|
|
|
? ['Remove', 'Restore']
|
2020-02-03 12:18:45 +05:00
|
|
|
: ['Add to', 'Share', 'Export', 'Delete', 'Open'],
|
2020-02-02 19:09:33 +05:00
|
|
|
isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'],
|
2020-01-16 19:55:52 +05:00
|
|
|
);
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
2019-12-04 19:38:19 +05:00
|
|
|
</View>
|
2020-01-16 19:55:52 +05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|