2020-01-18 18:14:57 +05:00
|
|
|
import React from 'react';
|
2020-09-09 14:55:59 +05:00
|
|
|
import {Text, TouchableOpacity, View} from 'react-native';
|
2020-02-11 20:33:36 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-09-09 14:55:59 +05:00
|
|
|
import {ph, pv, SIZE, WEIGHT} from '../../common/common';
|
|
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {ACTIONS} from '../../provider/actions';
|
2020-03-21 10:03:11 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
2020-09-09 14:55:59 +05:00
|
|
|
import {db, ToastEvent} from '../../utils/utils';
|
|
|
|
|
import {Button} from '../Button';
|
|
|
|
|
import {ActionSheetEvent, moveNoteHideEvent} from '../DialogManager/recievers';
|
|
|
|
|
import Seperator from '../Seperator';
|
2020-01-07 16:26:30 +05:00
|
|
|
|
2019-12-05 17:40:09 +05:00
|
|
|
export const NotebookItem = ({
|
|
|
|
|
item,
|
2019-12-09 13:17:40 +05:00
|
|
|
hideMore = false,
|
2019-12-05 17:40:09 +05:00
|
|
|
isTopic = false,
|
2019-12-09 13:17:40 +05:00
|
|
|
notebookID,
|
2019-12-14 16:00:16 +05:00
|
|
|
numColumns,
|
2019-12-21 09:46:08 +05:00
|
|
|
isTrash,
|
2020-01-13 17:33:41 +05:00
|
|
|
customStyle,
|
2019-12-05 17:40:09 +05:00
|
|
|
}) => {
|
2020-01-17 21:26:01 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
2020-02-02 16:18:52 +05:00
|
|
|
const {colors, selectedItemsList} = state;
|
2020-01-17 00:23:16 +05:00
|
|
|
|
2019-12-09 13:17:40 +05:00
|
|
|
return (
|
|
|
|
|
<View
|
2020-01-13 17:33:41 +05:00
|
|
|
style={[
|
|
|
|
|
{
|
2020-09-09 14:55:59 +05:00
|
|
|
height: isTopic ? 80 : 120,
|
|
|
|
|
justifyContent: 'space-between',
|
2020-01-13 17:33:41 +05:00
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
paddingRight: 6,
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
borderBottomColor: colors.nav,
|
2020-09-09 14:55:59 +05:00
|
|
|
width: '100%',
|
2020-01-13 17:33:41 +05:00
|
|
|
},
|
|
|
|
|
customStyle,
|
|
|
|
|
]}>
|
2019-12-03 22:05:47 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-09 14:55:59 +05:00
|
|
|
width: hideMore ? '80%' : '90%',
|
|
|
|
|
maxWidth: hideMore ? '80%' : '90%',
|
|
|
|
|
minHeight: 50,
|
|
|
|
|
justifyContent: 'center',
|
2019-12-03 22:05:47 +05:00
|
|
|
}}>
|
2020-09-09 14:55:59 +05:00
|
|
|
<Text
|
|
|
|
|
numberOfLines={1}
|
2020-01-07 16:26:30 +05:00
|
|
|
style={{
|
2020-09-09 14:55:59 +05:00
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
fontSize: SIZE.md,
|
|
|
|
|
color: colors.heading,
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}>
|
|
|
|
|
{item.title}
|
|
|
|
|
</Text>
|
|
|
|
|
{isTopic || !item.description ? null : (
|
2019-12-03 22:05:47 +05:00
|
|
|
<Text
|
2020-09-09 14:55:59 +05:00
|
|
|
numberOfLines={numColumns === 2 ? 3 : 2}
|
2019-12-03 22:05:47 +05:00
|
|
|
style={{
|
2020-09-09 14:55:59 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xs + 1,
|
|
|
|
|
lineHeight: SIZE.sm,
|
|
|
|
|
color: colors.pri,
|
2019-12-03 22:05:47 +05:00
|
|
|
maxWidth: '100%',
|
2020-09-09 14:55:59 +05:00
|
|
|
paddingVertical: 5,
|
|
|
|
|
height: numColumns === 2 ? SIZE.sm * 3.5 : null,
|
2019-12-03 22:05:47 +05:00
|
|
|
}}>
|
2020-09-09 14:55:59 +05:00
|
|
|
{item.description}
|
2019-12-03 22:05:47 +05:00
|
|
|
</Text>
|
2020-09-09 14:55:59 +05:00
|
|
|
)}
|
2019-12-03 22:05:47 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
{isTopic ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
width: '80%',
|
|
|
|
|
maxWidth: '80%',
|
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
}}>
|
|
|
|
|
{item && item.topics ? (
|
|
|
|
|
item.topics.slice(1, 4).map((topic) => (
|
|
|
|
|
<View
|
|
|
|
|
key={topic.dateCreated.toString() + topic.title}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 2.5,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
paddingHorizontal: ph / 1.5,
|
|
|
|
|
paddingVertical: pv / 3,
|
|
|
|
|
marginRight: 5,
|
|
|
|
|
marginVertical: 2.5,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
numberOfLines={1}
|
|
|
|
|
style={{
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.xxs,
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
}}>
|
|
|
|
|
{topic.title}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
2019-12-21 09:46:08 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
2020-09-09 14:55:59 +05:00
|
|
|
fontSize: SIZE.xxs,
|
|
|
|
|
paddingVertical: pv / 3,
|
|
|
|
|
maxWidth: '100%',
|
2019-12-21 09:46:08 +05:00
|
|
|
}}>
|
2020-09-09 14:55:59 +05:00
|
|
|
This notebook has no topics.
|
2019-12-21 09:46:08 +05:00
|
|
|
</Text>
|
2020-09-09 14:55:59 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
|
|
|
|
)}
|
2019-12-21 09:46:08 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
{isTrash ? (
|
2020-03-17 10:24:53 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
2019-12-06 12:06:03 +05:00
|
|
|
style={{
|
2020-03-17 10:24:53 +05:00
|
|
|
color: colors.icon,
|
2020-09-09 14:55:59 +05:00
|
|
|
fontSize: SIZE.xs - 1,
|
2020-03-17 10:24:53 +05:00
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
2019-12-06 12:06:03 +05:00
|
|
|
}}>
|
2020-09-09 14:55:59 +05:00
|
|
|
{'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) + ' '}
|
2020-03-17 10:24:53 +05:00
|
|
|
</Text>
|
|
|
|
|
</View>
|
2020-09-09 14:55:59 +05:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
}}>
|
|
|
|
|
{isTrash ? null : (
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.xxs,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}>
|
|
|
|
|
{new Date(item.dateCreated).toDateString().substring(4)}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
<Seperator half />
|
|
|
|
|
<Text
|
2019-12-06 11:09:45 +05:00
|
|
|
style={{
|
2020-09-09 14:55:59 +05:00
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.xxs,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}>
|
|
|
|
|
{item && item.totalNotes && item.totalNotes > 1
|
|
|
|
|
? item.totalNotes + ' Notes'
|
|
|
|
|
: item.totalNotes === 1
|
|
|
|
|
? item.totalNotes + ' Note'
|
|
|
|
|
: '0 Notes'}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
{hideMore ||
|
|
|
|
|
(item.title === 'General' && item.type === 'topic') ? null : (
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minHeight: 70,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
let rowItems = isTrash
|
|
|
|
|
? ['Restore', 'Remove']
|
|
|
|
|
: [
|
|
|
|
|
item.type == 'topic' ? 'Edit Topic' : 'Edit Notebook',
|
|
|
|
|
'Delete',
|
|
|
|
|
];
|
2020-01-18 18:14:57 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
let columnItems = item.type === 'topic' ? [] : ['Pin'];
|
2020-01-18 18:14:57 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
ActionSheetEvent(item, false, false, rowItems, columnItems, {
|
|
|
|
|
notebookID: notebookID,
|
|
|
|
|
});
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="dots-horizontal" size={SIZE.lg} color={colors.heading} />
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
)}
|
2020-01-10 18:46:52 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
{hideMore && isTopic ? (
|
|
|
|
|
<Button
|
|
|
|
|
width="20%"
|
|
|
|
|
title="Move"
|
|
|
|
|
onPress={async () => {
|
|
|
|
|
let noteIds = [];
|
|
|
|
|
selectedItemsList.forEach((item) => noteIds.push(item.id));
|
2020-03-02 15:16:46 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
await db.notes.move(
|
|
|
|
|
{
|
|
|
|
|
topic: item.title,
|
|
|
|
|
id: item.notebookId,
|
|
|
|
|
},
|
|
|
|
|
...noteIds,
|
|
|
|
|
);
|
|
|
|
|
dispatch({type: ACTIONS.CLEAR_SELECTION});
|
2020-01-18 18:14:57 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
moveNoteHideEvent();
|
2019-12-11 15:20:18 +05:00
|
|
|
|
2020-09-09 14:55:59 +05:00
|
|
|
ToastEvent.show(`Note moved to ${item.title}`, 'success');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2019-12-09 13:17:40 +05:00
|
|
|
</View>
|
2019-12-03 22:05:47 +05:00
|
|
|
);
|
|
|
|
|
};
|