2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-08-31 06:33:37 +05:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-08-30 16:13:11 +05:00
|
|
|
|
2023-11-22 11:16:15 +05:00
|
|
|
import { useThemeColors } from "@notesnook/theme";
|
2023-11-16 08:54:37 +05:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-11-22 11:16:15 +05:00
|
|
|
import { View } from "react-native";
|
2022-08-26 16:19:39 +05:00
|
|
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
|
|
|
|
import { db } from "../../common/database";
|
2023-08-29 20:42:45 +05:00
|
|
|
import NotebookScreen from "../../screens/notebook";
|
2023-11-22 11:16:15 +05:00
|
|
|
import { eSendEvent, presentSheet } from "../../services/event-manager";
|
|
|
|
|
import { eClearEditor } from "../../utils/events";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { SIZE } from "../../utils/size";
|
|
|
|
|
import { Button } from "../ui/button";
|
|
|
|
|
import Heading from "../ui/typography/heading";
|
2021-12-27 18:09:00 +05:00
|
|
|
|
2023-02-09 15:34:29 +05:00
|
|
|
export default function Notebooks({ note, close, full }) {
|
2023-08-01 12:07:21 +05:00
|
|
|
const { colors } = useThemeColors();
|
2023-11-16 08:54:37 +05:00
|
|
|
async function getNotebooks(item) {
|
2023-02-09 15:34:29 +05:00
|
|
|
let filteredNotebooks = [];
|
2023-11-16 08:54:37 +05:00
|
|
|
const relations = await db.relations.to(note, "notebook").resolve();
|
|
|
|
|
filteredNotebooks.push(relations);
|
|
|
|
|
if (!item.notebooks || item.notebooks.length < 1) return filteredNotebooks;
|
2023-02-09 15:34:29 +05:00
|
|
|
return filteredNotebooks;
|
2021-12-27 18:09:00 +05:00
|
|
|
}
|
2023-11-16 08:54:37 +05:00
|
|
|
const [noteNotebooks, setNoteNotebooks] = useState([]);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getNotebooks().then((notebooks) => setNoteNotebooks(notebooks));
|
|
|
|
|
});
|
2021-12-27 18:09:00 +05:00
|
|
|
|
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;
|
2023-08-29 20:42:45 +05:00
|
|
|
NotebookScreen.navigate(item, true);
|
2021-12-27 18:09:00 +05:00
|
|
|
};
|
|
|
|
|
|
2023-02-09 15:34:29 +05:00
|
|
|
const renderItem = (item) => (
|
2021-12-27 18:09:00 +05:00
|
|
|
<View
|
2023-02-09 15:34:29 +05:00
|
|
|
key={item.id}
|
2021-12-27 18:09:00 +05:00
|
|
|
style={{
|
2023-02-09 15:34:29 +05:00
|
|
|
justifyContent: "flex-start",
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
flexShrink: 1,
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
padding: 6,
|
|
|
|
|
borderWidth: full ? 0 : 1,
|
2023-08-01 12:07:21 +05:00
|
|
|
borderColor: colors.primary.background,
|
2023-02-09 15:34:29 +05:00
|
|
|
borderRadius: 10,
|
2023-08-01 12:07:21 +05:00
|
|
|
backgroundColor: full ? "transparent" : colors.secondary.background,
|
2023-03-17 16:18:57 +05:00
|
|
|
minHeight: 42
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2023-02-09 15:34:29 +05:00
|
|
|
<Icon
|
|
|
|
|
name="book-outline"
|
2023-08-01 12:07:21 +05:00
|
|
|
color={colors.primary.accent}
|
2023-02-09 15:34:29 +05:00
|
|
|
size={SIZE.sm}
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 5
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Heading
|
|
|
|
|
numberOfLines={1}
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: "50%"
|
|
|
|
|
}}
|
|
|
|
|
size={SIZE.sm}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
navigateNotebook(item.id);
|
2023-04-26 15:39:09 +05:00
|
|
|
eSendEvent(eClearEditor);
|
2023-02-09 15:34:29 +05:00
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{item.title}
|
|
|
|
|
</Heading>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
|
2023-03-17 16:18:57 +05:00
|
|
|
return noteNotebooks.length === 0 ? null : (
|
2023-02-09 15:34:29 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
marginTop: 6
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{full
|
|
|
|
|
? noteNotebooks.map(renderItem)
|
|
|
|
|
: noteNotebooks.slice(0, 1).map(renderItem)}
|
|
|
|
|
|
|
|
|
|
{noteNotebooks.length > 1 && !full ? (
|
|
|
|
|
<Button
|
|
|
|
|
title={`See all linked notebooks`}
|
2023-04-27 08:18:25 +05:00
|
|
|
fontSize={SIZE.xs}
|
2023-02-09 15:34:29 +05:00
|
|
|
style={{
|
|
|
|
|
alignSelf: "flex-end",
|
|
|
|
|
marginRight: 12,
|
|
|
|
|
paddingHorizontal: 0,
|
|
|
|
|
backgroundColor: "transparent"
|
|
|
|
|
}}
|
|
|
|
|
type="gray"
|
|
|
|
|
textStyle={{
|
|
|
|
|
textDecorationLine: "underline"
|
|
|
|
|
}}
|
|
|
|
|
height={20}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
presentSheet({
|
|
|
|
|
context: "properties",
|
|
|
|
|
component: (ref, close) => (
|
|
|
|
|
<Notebooks note={note} close={close} full={true} />
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : undefined}
|
2021-12-27 18:09:00 +05:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|