2019-12-03 22:05:47 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
|
import {View, Text, TouchableOpacity} from 'react-native';
|
|
|
|
|
import NavigationService from '../../services/NavigationService';
|
2019-12-06 11:09:45 +05:00
|
|
|
import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';
|
2019-12-03 22:05:47 +05:00
|
|
|
import {
|
|
|
|
|
COLOR_SCHEME,
|
|
|
|
|
SIZE,
|
|
|
|
|
br,
|
|
|
|
|
ph,
|
|
|
|
|
pv,
|
|
|
|
|
opacity,
|
|
|
|
|
FONT,
|
|
|
|
|
WEIGHT,
|
|
|
|
|
} from '../../common/common';
|
|
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2019-12-06 11:09:45 +05:00
|
|
|
import {w} from '../../utils/utils';
|
2019-12-05 17:40:09 +05:00
|
|
|
export const NotebookItem = ({
|
|
|
|
|
item,
|
|
|
|
|
index,
|
|
|
|
|
colors,
|
|
|
|
|
hideMore,
|
2019-12-06 11:09:45 +05:00
|
|
|
topic,
|
2019-12-05 17:40:09 +05:00
|
|
|
isTopic = false,
|
|
|
|
|
}) => {
|
2019-12-06 11:09:45 +05:00
|
|
|
let setMenuRef = {};
|
2019-12-03 22:05:47 +05:00
|
|
|
return (
|
|
|
|
|
<TouchableOpacity
|
2019-12-06 11:09:45 +05:00
|
|
|
activeOpacity={opacity}
|
2019-12-03 22:05:47 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
NavigationService.navigate('Notebook', {
|
|
|
|
|
notebook: item,
|
2019-12-06 11:09:45 +05:00
|
|
|
title: hideMore ? 'Choose topic' : item.title,
|
2019-12-05 17:40:09 +05:00
|
|
|
isMove: hideMore ? true : false,
|
|
|
|
|
hideMore: hideMore ? true : false,
|
2019-12-03 22:05:47 +05:00
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
marginHorizontal: '5%',
|
|
|
|
|
borderBottomWidth: 1,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderBottomColor: colors.nav,
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingVertical: pv,
|
2019-12-03 22:05:47 +05:00
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
<View>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
fontSize: SIZE.md,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}>
|
2019-12-06 11:09:45 +05:00
|
|
|
{item.title}
|
2019-12-03 22:05:47 +05:00
|
|
|
</Text>
|
2019-12-06 11:09:45 +05:00
|
|
|
{isTopic ? null : (
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xs + 1,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}>
|
|
|
|
|
{item.description}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{isTopic ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
}}>
|
|
|
|
|
{Object.keys(item.topics)
|
|
|
|
|
.slice(0, 3)
|
|
|
|
|
.map(topic => (
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
color: 'white',
|
|
|
|
|
marginRight: 5,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xxs,
|
|
|
|
|
paddingHorizontal: ph / 2,
|
|
|
|
|
paddingVertical: pv / 4,
|
|
|
|
|
}}>
|
|
|
|
|
{topic}
|
|
|
|
|
</Text>
|
|
|
|
|
))}
|
|
|
|
|
</View>
|
|
|
|
|
)}
|
2019-12-03 22:05:47 +05:00
|
|
|
|
2019-12-06 12:06:03 +05:00
|
|
|
{isTopic ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
style={{width: 30}}
|
|
|
|
|
name="lock"
|
|
|
|
|
size={SIZE.sm}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<Icon
|
|
|
|
|
style={{width: 30}}
|
|
|
|
|
name="star"
|
|
|
|
|
size={SIZE.sm}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
2019-12-06 11:09:45 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
2019-12-06 12:06:03 +05:00
|
|
|
fontSize: SIZE.xxs + 2,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
2019-12-06 11:09:45 +05:00
|
|
|
}}>
|
2019-12-06 12:06:03 +05:00
|
|
|
{new Date(item.dateCreated).toDateString().substring(4)}
|
2019-12-06 11:09:45 +05:00
|
|
|
</Text>
|
2019-12-06 12:06:03 +05:00
|
|
|
</View>
|
|
|
|
|
)}
|
2019-12-03 22:05:47 +05:00
|
|
|
</View>
|
|
|
|
|
|
2019-12-05 17:40:09 +05:00
|
|
|
{hideMore ? null : (
|
2019-12-06 11:09:45 +05:00
|
|
|
<Menu
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
}}
|
|
|
|
|
ref={ref => (setMenuRef[index] = ref)}
|
|
|
|
|
button={
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
style={{
|
|
|
|
|
width: w * 0.05,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}
|
|
|
|
|
onPress={() => setMenuRef[index].show()}>
|
|
|
|
|
<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>
|
|
|
|
|
<MenuItem
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setMenuRef[props.index].hide();
|
|
|
|
|
ToastEvent.show(
|
|
|
|
|
'Note added to favorites.',
|
|
|
|
|
'success',
|
|
|
|
|
3000,
|
|
|
|
|
() => {},
|
|
|
|
|
'Ok',
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="star" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Favorite
|
|
|
|
|
</MenuItem>
|
2019-12-06 11:09:45 +05:00
|
|
|
<MenuItem
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setVisible(true);
|
|
|
|
|
setMenuRef[index].hide();
|
|
|
|
|
}}
|
|
|
|
|
textStyle={{
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="trash" size={SIZE.sm} color={colors.icon} />
|
|
|
|
|
{' '}Delete
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuDivider />
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
</Menu>
|
2019-12-05 17:40:09 +05:00
|
|
|
)}
|
|
|
|
|
{hideMore && isTopic ? (
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
NavigationService.navigate('Home');
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '20%',
|
|
|
|
|
paddingHorizontal: ph - 5,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderColor: colors.nav,
|
2019-12-05 17:40:09 +05:00
|
|
|
paddingVertical: pv,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: SIZE.xs,
|
|
|
|
|
fontFamily: WEIGHT.semibold,
|
|
|
|
|
color: 'white',
|
|
|
|
|
}}>
|
|
|
|
|
Move
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
) : null}
|
2019-12-03 22:05:47 +05:00
|
|
|
</View>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
);
|
|
|
|
|
};
|