2022-08-29 16:19:17 +05:00
|
|
|
import React from "react";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { ScrollView, View } from "react-native";
|
|
|
|
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
|
|
|
|
import { db } from "../../common/database";
|
2022-08-29 16:19:17 +05:00
|
|
|
import Notebook from "../../screens/notebook";
|
|
|
|
|
import { TopicNotes } from "../../screens/notes/topic-notes";
|
|
|
|
|
import { useThemeStore } from "../../stores/use-theme-store";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { SIZE } from "../../utils/size";
|
|
|
|
|
import { Button } from "../ui/button";
|
|
|
|
|
import { PressableButton } from "../ui/pressable";
|
|
|
|
|
import Heading from "../ui/typography/heading";
|
2022-01-22 12:57:05 +05:00
|
|
|
export default function Notebooks({ note, close }) {
|
2022-08-26 16:19:39 +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
|
2022-08-26 16:19:39 +05:00
|
|
|
.map((item) => {
|
2021-12-27 18:09:00 +05:00
|
|
|
let topic = item_notebook.topics.topic(item)?._topic;
|
|
|
|
|
if (!topic) return null;
|
|
|
|
|
return {
|
|
|
|
|
id: topic.id,
|
|
|
|
|
title: topic.title
|
|
|
|
|
};
|
|
|
|
|
})
|
2022-08-26 16:19:39 +05:00
|
|
|
.filter((i) => i !== null)
|
2021-12-27 18:09:00 +05:00
|
|
|
};
|
|
|
|
|
notebooks.push(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return notebooks;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 16:19:39 +05:00
|
|
|
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={{
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
2021-12-27 18:09:00 +05:00
|
|
|
borderTopWidth: 1,
|
|
|
|
|
borderTopColor: colors.nav
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-08-26 16:19:39 +05:00
|
|
|
{getNotebooks(note).map((item) => (
|
2021-12-27 18:09:00 +05:00
|
|
|
<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={{
|
2022-08-26 16:19:39 +05:00
|
|
|
justifyContent: "flex-start",
|
2021-12-27 18:09:00 +05:00
|
|
|
paddingHorizontal: 12,
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
2021-12-27 18:09:00 +05:00
|
|
|
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={{
|
2022-08-26 16:19:39 +05:00
|
|
|
maxWidth: "50%"
|
2021-12-27 18:09:00 +05:00
|
|
|
}}
|
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={{
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
2021-12-27 18:09:00 +05:00
|
|
|
marginLeft: 8,
|
|
|
|
|
borderLeftColor: colors.nav,
|
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
|
paddingLeft: 8
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-08-26 16:19:39 +05:00
|
|
|
{item.topics.map((topic) => (
|
2021-12-27 18:09:00 +05:00
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
}
|