2021-12-27 18:09:00 +05:00
|
|
|
import React from 'react';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { ScrollView, View } from 'react-native';
|
2021-12-27 18:09:00 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { useThemeStore } from '../../stores/use-theme-store';
|
2022-02-28 23:25:18 +05:00
|
|
|
import { eSendEvent } from '../../services/event-manager';
|
|
|
|
|
import Navigation from '../../services/navigation';
|
2022-08-16 16:48:10 +05:00
|
|
|
import { db } from '../../common/database';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { eOnNewTopicAdded, refreshNotesPage } from '../../utils/events';
|
|
|
|
|
import { SIZE } from '../../utils/size';
|
|
|
|
|
import { Button } from '../ui/button';
|
|
|
|
|
import { PressableButton } from '../ui/pressable';
|
|
|
|
|
import Heading from '../ui/typography/heading';
|
2022-04-24 16:49:33 +05:00
|
|
|
import { TopicNotes } from '../../screens/notes/topic-notes';
|
|
|
|
|
import Notebook from '../../screens/notebook';
|
2021-12-27 18:09:00 +05:00
|
|
|
|
2022-01-22 12:57:05 +05:00
|
|
|
export default function Notebooks({ note, close }) {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2021-12-27 18:09:00 +05:00
|
|
|
|
|
|
|
|
function getNotebooks(item) {
|
|
|
|
|
if (!item.notebooks || item.notebooks.length < 1) return [];
|
|
|
|
|
let notebooks = [];
|
|
|
|
|
for (let notebook of item.notebooks) {
|
|
|
|
|
let item_notebook = db.notebooks.notebook(notebook.id);
|
|
|
|
|
console.log(notebook);
|
|
|
|
|
if (item_notebook) {
|
|
|
|
|
let data = {
|
|
|
|
|
id: notebook.id,
|
|
|
|
|
title: item_notebook.title,
|
|
|
|
|
topics: notebook.topics
|
|
|
|
|
.map(item => {
|
|
|
|
|
let topic = item_notebook.topics.topic(item)?._topic;
|
|
|
|
|
if (!topic) return null;
|
|
|
|
|
return {
|
|
|
|
|
id: topic.id,
|
|
|
|
|
title: topic.title
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
.filter(i => i !== null)
|
|
|
|
|
};
|
|
|
|
|
notebooks.push(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return notebooks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const navigateNotebook = id => {
|
2022-04-24 05:59:14 +05:00
|
|
|
let item = db.notebooks.notebook(id)?.data;
|
|
|
|
|
if (!item) return;
|
2022-04-24 16:49:33 +05:00
|
|
|
Notebook.navigate(item, true);
|
2021-12-27 18:09:00 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const navigateTopic = (id, notebookId) => {
|
2022-04-24 05:59:14 +05:00
|
|
|
let item = db.notebooks.notebook(notebookId)?.topics?.topic(id)?._topic;
|
|
|
|
|
if (!item) return;
|
2022-04-24 16:49:33 +05:00
|
|
|
TopicNotes.navigate(item, true);
|
2021-12-27 18:09:00 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return !note.notebooks || note.notebooks.length === 0 ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
borderTopWidth: 1,
|
|
|
|
|
borderTopColor: colors.nav
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-12-27 18:09:00 +05:00
|
|
|
{getNotebooks(note).map(item => (
|
|
|
|
|
<PressableButton
|
2022-01-22 12:57:05 +05:00
|
|
|
key={item.id}
|
2021-12-27 18:09:00 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
navigateNotebook(item.id);
|
|
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
customStyle={{
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexShrink: 1,
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
marginTop: 5,
|
|
|
|
|
paddingVertical: 6
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-12-27 18:09:00 +05:00
|
|
|
<Icon
|
|
|
|
|
name="book-outline"
|
|
|
|
|
color={colors.accent}
|
|
|
|
|
size={SIZE.sm + 1}
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 5
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Heading
|
|
|
|
|
numberOfLines={1}
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: '50%'
|
|
|
|
|
}}
|
2022-01-22 12:57:05 +05:00
|
|
|
size={SIZE.sm}
|
|
|
|
|
>
|
2021-12-27 18:09:00 +05:00
|
|
|
{item.title}
|
|
|
|
|
</Heading>
|
|
|
|
|
|
|
|
|
|
<ScrollView
|
|
|
|
|
horizontal={true}
|
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
marginLeft: 8,
|
|
|
|
|
borderLeftColor: colors.nav,
|
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
|
paddingLeft: 8
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-12-27 18:09:00 +05:00
|
|
|
{item.topics.map(topic => (
|
|
|
|
|
<Button
|
2022-01-22 12:57:05 +05:00
|
|
|
key={topic.id}
|
2021-12-27 18:09:00 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
navigateTopic(topic.id, item.id);
|
|
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
title={topic.title}
|
|
|
|
|
type="grayBg"
|
|
|
|
|
height={22}
|
|
|
|
|
fontSize={SIZE.xs + 1}
|
|
|
|
|
icon="bookmark-outline"
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 5,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 8
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2022-01-22 12:57:05 +05:00
|
|
|
<View style={{ width: 10 }} />
|
2021-12-27 18:09:00 +05:00
|
|
|
</ScrollView>
|
|
|
|
|
</PressableButton>
|
|
|
|
|
))}
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|