Files
notesnook/apps/mobile/src/components/NoteItem/index.js

245 lines
7.3 KiB
JavaScript
Raw Normal View History

2020-01-16 19:55:52 +05:00
import React from 'react';
2020-09-27 10:15:19 +05:00
import { Dimensions, Text, View } from 'react-native';
2020-02-11 20:33:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-27 10:15:19 +05:00
import { ph, SIZE, WEIGHT } from '../../common/common';
import { timeSince } from '../../utils/utils';
import { ActionIcon } from '../ActionIcon';
import { ActionSheetEvent } from '../DialogManager/recievers';
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-02-07 00:26:44 +05:00
this.colors = [];
2020-01-16 19:55:52 +05:00
this.actionSheet;
this.show = null;
this.setMenuRef = {};
this.willRefresh = false;
}
shouldComponentUpdate(nextProps, nextState) {
2020-02-07 00:26:44 +05:00
if (
nextProps.item.locked !== this.cipher.value ||
2020-03-03 11:01:50 +05:00
nextProps.item.colors.length !== this.colors.length ||
nextProps.selectionMode !== this.props.selectionMode
2020-02-07 00:26:44 +05:00
) {
2020-01-17 21:05:53 +05:00
return true;
} else {
return (
JSON.stringify(nextProps) !== JSON.stringify(this.props) ||
nextState !== this.state
);
}
}
componentDidUpdate() {
2020-02-07 00:26:44 +05:00
this.colors = [...this.props.item.colors];
2020-01-17 21:05:53 +05:00
this.cipher.value = this.props.item.locked ? true : false;
}
componentWillUnmount() {
2020-02-07 00:26:44 +05:00
this.colors = [];
2020-01-17 21:05:53 +05:00
this.cipher.value = false;
}
componentDidMount() {
2020-02-07 00:26:44 +05:00
this.colors = [];
2020-01-17 21:05:53 +05:00
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() {
2020-09-09 14:55:59 +05:00
let {colors, item, customStyle, isTrash} = this.props;
2020-01-16 19:55:52 +05:00
return (
<View
style={[
{
justifyContent: 'flex-start',
2019-12-21 09:46:08 +05:00
alignItems: 'center',
2020-01-16 19:55:52 +05:00
flexDirection: 'row',
2020-09-21 15:40:19 +05:00
width: '100%',
2020-02-02 23:43:46 +05:00
paddingRight: 6,
2020-01-16 19:55:52 +05:00
alignSelf: 'center',
borderBottomWidth: 1,
2020-09-09 14:55:59 +05:00
height: 100,
2020-09-21 15:40:19 +05:00
borderBottomColor: item.pinned ? 'transparent' : colors.nav,
2020-01-16 19:55:52 +05:00
},
customStyle ? customStyle : {},
]}>
2020-09-09 14:55:59 +05:00
<View
2020-01-16 19:55:52 +05:00
style={{
paddingLeft: 0,
2020-09-21 15:40:19 +05:00
width: '92%',
2020-01-16 19:55:52 +05:00
}}>
2020-09-09 14:55:59 +05:00
<Text
numberOfLines={1}
style={{
color: colors.heading,
2020-09-09 22:09:57 +05:00
fontSize: SIZE.md,
2020-09-09 14:55:59 +05:00
fontFamily: WEIGHT.bold,
maxWidth: '100%',
}}>
{item.title.replace('\n', '')}
</Text>
<View
style={{
justifyContent: 'flex-start',
alignItems: 'flex-start',
width: '100%',
}}>
2019-11-28 21:40:37 +05:00
<Text
2020-09-09 14:55:59 +05:00
numberOfLines={2}
2019-11-28 21:40:37 +05:00
style={{
2020-09-09 22:09:57 +05:00
fontSize: SIZE.xs + 1,
2020-09-09 14:55:59 +05:00
color: colors.pri + 'B3',
fontFamily: WEIGHT.regular,
width: '100%',
2020-02-02 23:43:46 +05:00
maxWidth: '100%',
2020-09-09 14:55:59 +05:00
paddingRight: ph,
2019-11-28 21:40:37 +05:00
}}>
2020-09-09 14:55:59 +05:00
{item.headline[item.headline.length - 1] === '\n'
? item.headline.slice(0, item.headline.length - 1)
: item.headline}
2019-11-28 21:40:37 +05:00
</Text>
2020-09-09 14:55:59 +05:00
2019-12-06 12:06:03 +05:00
<View
2019-11-28 21:40:37 +05:00
style={{
2020-09-09 14:55:59 +05:00
flexDirection: 'row',
2019-12-06 12:06:03 +05:00
justifyContent: 'flex-start',
2020-09-09 14:55:59 +05:00
alignItems: 'center',
2020-01-06 19:03:21 +05:00
width: '100%',
2020-09-09 14:55:59 +05:00
marginTop: 5,
2019-11-28 21:40:37 +05:00
}}>
2020-09-09 14:55:59 +05:00
{!isTrash ? (
<>
{item.colors.length > 0 ? (
<View
2020-01-10 18:46:52 +05:00
style={{
marginRight: 10,
2020-09-09 14:55:59 +05:00
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
2020-01-10 18:46:52 +05:00
}}>
2020-09-09 14:55:59 +05:00
{item.colors.map((item) => (
<View
key={item}
style={{
width: SIZE.xs,
height: SIZE.xs,
borderRadius: 100,
backgroundColor: item,
marginRight: -4.5,
}}
/>
))}
</View>
) : null}
2019-12-06 12:06:03 +05:00
2020-09-09 14:55:59 +05:00
{item.locked ? (
<Icon
style={{marginRight: 10}}
name="lock"
size={SIZE.xs}
color={colors.icon}
/>
) : null}
2020-04-06 13:38:03 +05:00
2020-09-09 14:55:59 +05:00
{item.favorite ? (
<Icon
style={{marginRight: 10}}
name="star"
size={SIZE.xs + 1}
color="orange"
/>
) : null}
<Text
2020-04-06 13:38:03 +05:00
style={{
2020-09-09 14:55:59 +05:00
color: colors.icon,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
marginRight: 10,
2020-04-20 09:16:01 +05:00
}}>
2020-09-09 14:55:59 +05:00
{timeSince(item.dateCreated)}
</Text>
</>
) : null}
{isTrash ? (
<>
<Text
style={{
color: colors.icon,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
}}>
{'Deleted on: ' + item && item.dateDeleted
? new Date(item.dateDeleted).toISOString().slice(0, 10)
: null + ' '}
</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}
{item.conflicted ? (
<View
style={{
backgroundColor: colors.errorText,
borderRadius: 2.5,
paddingHorizontal: 4,
position: 'absolute',
right: 20,
}}>
<Text
style={{
fontSize: SIZE.xs - 1,
color: 'white',
}}>
CONFLICTS
</Text>
</View>
) : null}
2019-12-06 12:06:03 +05:00
</View>
2020-09-09 14:55:59 +05:00
</View>
</View>
2019-11-28 21:40:37 +05:00
2020-09-21 15:40:19 +05:00
<ActionIcon
color={colors.heading}
name="dots-horizontal"
size={SIZE.xl}
2020-09-07 21:23:38 +05:00
onPress={() => {
ActionSheetEvent(
item,
isTrash ? false : true,
isTrash ? false : true,
isTrash
? ['Remove', 'Restore']
2020-09-14 13:14:07 +05:00
: ['Add to', 'Share', 'Export', 'Delete', 'Copy'],
2020-09-07 21:23:38 +05:00
isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'],
);
2020-09-21 15:40:19 +05:00
}}
customStyle={{
justifyContent: 'center',
height: 35,
width: 35,
borderRadius: 100,
alignItems: 'center',
}}
/>
2019-12-04 19:38:19 +05:00
</View>
2020-01-16 19:55:52 +05:00
);
}
}