2019-12-04 19:38:19 +05:00
|
|
|
import React, {useState, createRef} from 'react';
|
2019-11-17 16:02:19 +05:00
|
|
|
import {
|
|
|
|
|
View,
|
|
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
ScrollView,
|
|
|
|
|
Dimensions,
|
|
|
|
|
FlatList,
|
2019-11-28 21:40:37 +05:00
|
|
|
TouchableWithoutFeedback,
|
2019-11-29 11:31:43 +05:00
|
|
|
Platform,
|
2019-11-17 16:02:19 +05:00
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
COLOR_SCHEME,
|
|
|
|
|
SIZE,
|
|
|
|
|
br,
|
|
|
|
|
ph,
|
|
|
|
|
pv,
|
|
|
|
|
opacity,
|
|
|
|
|
FONT,
|
|
|
|
|
WEIGHT,
|
|
|
|
|
} from '../../common/common';
|
|
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2019-11-17 16:02:19 +05:00
|
|
|
import {Reminder} from '../Reminder';
|
2019-12-05 17:40:09 +05:00
|
|
|
import {getElevation, timeSince, ToastEvent} from '../../utils/utils';
|
2019-11-28 21:40:37 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
2019-12-04 19:38:19 +05:00
|
|
|
import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';
|
2019-12-05 17:40:09 +05:00
|
|
|
import {Dialog} from '../Dialog';
|
2019-12-07 08:41:48 +05:00
|
|
|
import {VaultDialog} from '../VaultDialog';
|
2019-12-11 01:10:04 +05:00
|
|
|
import {db} from '../../../App';
|
2019-12-09 13:17:40 +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
|
|
|
|
2019-11-17 16:02:19 +05:00
|
|
|
const NoteItem = props => {
|
|
|
|
|
const [colors, setColors] = useState(COLOR_SCHEME);
|
2019-12-05 17:40:09 +05:00
|
|
|
const [visible, setVisible] = useState(false);
|
2019-12-07 08:41:48 +05:00
|
|
|
const [vaultDialog, setVaultDialog] = useState(false);
|
2019-11-17 16:02:19 +05:00
|
|
|
const item = props.item;
|
2019-12-09 13:17:40 +05:00
|
|
|
|
|
|
|
|
let show = null;
|
|
|
|
|
|
2019-12-05 17:40:09 +05:00
|
|
|
let setMenuRef = {};
|
2019-12-09 13:17:40 +05:00
|
|
|
|
|
|
|
|
const onMenuHide = () => {
|
|
|
|
|
if (show) {
|
|
|
|
|
if (show === 'delete') {
|
|
|
|
|
setVisible(true);
|
|
|
|
|
show = null;
|
|
|
|
|
} else if (show == 'vault') {
|
|
|
|
|
setVaultDialog(true);
|
|
|
|
|
show = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const hideMenu = () => {
|
|
|
|
|
setMenuRef[props.index].hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const showMenu = () => {
|
|
|
|
|
setMenuRef[props.index].show();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteItem = async () => {
|
2019-12-11 01:10:04 +05:00
|
|
|
await db.deleteNotes([item]);
|
2019-12-09 13:17:40 +05:00
|
|
|
ToastEvent.show('Note moved to trash', 'success', 3000);
|
|
|
|
|
setVisible(false);
|
|
|
|
|
props.refresh();
|
|
|
|
|
};
|
2019-11-17 16:02:19 +05:00
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
marginHorizontal: w * 0.05,
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingVertical: pv,
|
|
|
|
|
|
2019-11-17 16:02:19 +05:00
|
|
|
borderRadius: br,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-11-28 21:40:37 +05:00
|
|
|
flexDirection: 'row',
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingHorizontal: ph,
|
2019-11-29 11:31:43 +05:00
|
|
|
width: Platform.isPad ? '95%' : '90%',
|
|
|
|
|
alignSelf: 'center',
|
2019-11-30 19:56:40 +05:00
|
|
|
borderBottomWidth: 1,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderBottomColor: colors.nav,
|
2019-11-17 16:02:19 +05:00
|
|
|
}}>
|
2019-12-05 17:40:09 +05:00
|
|
|
<Dialog
|
|
|
|
|
visible={visible}
|
|
|
|
|
title="Delete note"
|
|
|
|
|
icon="trash"
|
|
|
|
|
paragraph="Do you want to delete this note?"
|
|
|
|
|
positiveText="Delete"
|
2019-12-09 13:17:40 +05:00
|
|
|
positivePress={deleteItem}
|
2019-12-05 17:40:09 +05:00
|
|
|
close={() => {
|
|
|
|
|
setVisible(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2019-12-07 08:41:48 +05:00
|
|
|
<VaultDialog visible={vaultDialog} />
|
|
|
|
|
|
2019-11-28 21:40:37 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={1}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
NavigationService.navigate('Editor', {
|
|
|
|
|
note: item,
|
|
|
|
|
});
|
|
|
|
|
}}
|
2019-11-17 16:02:19 +05:00
|
|
|
style={{
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingLeft: ph,
|
|
|
|
|
width: '100%',
|
2019-11-17 16:02:19 +05:00
|
|
|
}}>
|
2019-11-28 21:40:37 +05:00
|
|
|
<>
|
|
|
|
|
<Text
|
|
|
|
|
numberOfLines={1}
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
fontSize: SIZE.md,
|
|
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
marginBottom: 5,
|
|
|
|
|
}}>
|
|
|
|
|
{item.title.replace('\n', '')}
|
|
|
|
|
</Text>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'flex-start',
|
|
|
|
|
width: '100%',
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
2019-12-05 17:40:09 +05:00
|
|
|
numberOfLines={2}
|
2019-11-28 21:40:37 +05:00
|
|
|
style={{
|
2019-11-29 11:31:43 +05:00
|
|
|
fontSize: SIZE.xs + 2,
|
2019-11-28 21:40:37 +05:00
|
|
|
color: colors.icon,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
width: '100%',
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
paddingRight: ph,
|
|
|
|
|
}}>
|
|
|
|
|
{item.headline}
|
|
|
|
|
</Text>
|
2019-11-17 17:48:56 +05:00
|
|
|
|
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
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
2019-11-28 21:40:37 +05:00
|
|
|
}}>
|
2019-12-06 12:06:03 +05:00
|
|
|
<Icon
|
|
|
|
|
style={{width: 30}}
|
|
|
|
|
name="lock"
|
|
|
|
|
size={SIZE.sm}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<Icon
|
|
|
|
|
style={{width: 30}}
|
|
|
|
|
name="star"
|
|
|
|
|
size={SIZE.sm}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
|
|
|
|
fontSize: SIZE.xxs + 2,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}>
|
|
|
|
|
{timeSince(item.dateCreated) + ' '}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
2019-11-28 21:40:37 +05:00
|
|
|
</View>
|
|
|
|
|
</>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
<View
|
2019-11-17 17:48:56 +05:00
|
|
|
style={{
|
2019-12-04 19:38:19 +05:00
|
|
|
width: w * 0.05,
|
2019-11-28 21:40:37 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingRight: ph,
|
2019-11-17 17:48:56 +05:00
|
|
|
}}>
|
2019-12-04 19:38:19 +05:00
|
|
|
<Menu
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 5,
|
2019-12-07 12:05:15 +05:00
|
|
|
backgroundColor: colors.nav,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}
|
2019-12-09 13:17:40 +05:00
|
|
|
onHidden={onMenuHide}
|
2019-12-04 19:38:19 +05:00
|
|
|
ref={ref => (setMenuRef[props.index] = ref)}
|
|
|
|
|
button={
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
style={{
|
|
|
|
|
width: w * 0.05,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}
|
2019-12-09 13:17:40 +05:00
|
|
|
onPress={showMenu}>
|
2019-12-04 19:38:19 +05:00
|
|
|
<Icon name="more-vertical" size={SIZE.lg} color={colors.icon} />
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
}>
|
2019-12-06 12:06:03 +05:00
|
|
|
<MenuItem
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="star" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Pin
|
|
|
|
|
</MenuItem>
|
2019-12-04 19:38:19 +05:00
|
|
|
<MenuItem
|
2019-12-05 17:40:09 +05:00
|
|
|
onPress={() => {
|
2019-12-09 13:17:40 +05:00
|
|
|
hideMenu();
|
2019-12-05 17:40:09 +05:00
|
|
|
ToastEvent.show(
|
|
|
|
|
'Note added to favorites.',
|
|
|
|
|
'success',
|
|
|
|
|
3000,
|
|
|
|
|
() => {},
|
|
|
|
|
'Ok',
|
|
|
|
|
);
|
|
|
|
|
}}
|
2019-12-04 19:38:19 +05:00
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
2019-12-05 17:40:09 +05:00
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="star" size={SIZE.sm} color={colors.icon} />
|
2019-12-05 17:40:09 +05:00
|
|
|
{' '}Favorite
|
2019-12-04 19:38:19 +05:00
|
|
|
</MenuItem>
|
2019-12-05 17:40:09 +05:00
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
<MenuItem
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="share" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Share
|
|
|
|
|
</MenuItem>
|
|
|
|
|
|
2019-12-05 17:40:09 +05:00
|
|
|
<MenuItem
|
|
|
|
|
onPress={() => {
|
2019-12-09 13:17:40 +05:00
|
|
|
hideMenu();
|
2019-12-09 17:03:49 +05:00
|
|
|
NavigationService.push('Folders', {
|
2019-12-05 17:40:09 +05:00
|
|
|
note: item,
|
|
|
|
|
title: 'Choose Notebook',
|
|
|
|
|
isMove: true,
|
|
|
|
|
hideMore: true,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="arrow-right" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Move
|
|
|
|
|
</MenuItem>
|
2019-12-07 08:41:48 +05:00
|
|
|
<MenuItem
|
|
|
|
|
onPress={() => {
|
2019-12-09 13:17:40 +05:00
|
|
|
show = 'vault';
|
|
|
|
|
hideMenu(true);
|
2019-12-07 08:41:48 +05:00
|
|
|
}}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="lock" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Lock
|
|
|
|
|
</MenuItem>
|
2019-12-05 17:40:09 +05:00
|
|
|
|
|
|
|
|
<MenuItem
|
|
|
|
|
onPress={() => {
|
2019-12-09 13:17:40 +05:00
|
|
|
show = 'delete';
|
|
|
|
|
hideMenu();
|
2019-12-05 17:40:09 +05:00
|
|
|
}}
|
2019-12-04 19:38:19 +05:00
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
2019-12-05 17:40:09 +05:00
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="trash" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Delete
|
|
|
|
|
</MenuItem>
|
2019-12-05 17:40:09 +05:00
|
|
|
<MenuDivider />
|
|
|
|
|
<MenuItem
|
|
|
|
|
disabled={true}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xs,
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: 0,
|
|
|
|
|
margin: 0,
|
|
|
|
|
height: 30,
|
|
|
|
|
}}>
|
|
|
|
|
Notebook: School Notes
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem
|
|
|
|
|
disabled={true}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xs,
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: 0,
|
|
|
|
|
margin: 0,
|
|
|
|
|
height: 30,
|
|
|
|
|
paddingBottom: 10,
|
|
|
|
|
}}>
|
|
|
|
|
{' '}- Topic: Physics
|
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
|
|
<MenuItem
|
|
|
|
|
disabled={true}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xs,
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: 0,
|
|
|
|
|
margin: 0,
|
|
|
|
|
height: 30,
|
|
|
|
|
paddingBottom: 10,
|
|
|
|
|
}}>
|
|
|
|
|
Created on: {new Date(item.dateCreated).toISOString().slice(0, 10)}
|
|
|
|
|
</MenuItem>
|
2019-12-04 19:38:19 +05:00
|
|
|
</Menu>
|
|
|
|
|
</View>
|
2019-11-17 16:02:19 +05:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default NoteItem;
|