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-02-09 15:29:30 +05:00
|
|
|
import React, {
|
|
|
|
|
createRef,
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
|
|
|
|
useMemo,
|
|
|
|
|
useState
|
|
|
|
|
} from "react";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { Keyboard, TouchableOpacity, View } from "react-native";
|
2023-02-09 15:29:30 +05:00
|
|
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
2022-08-29 16:19:17 +05:00
|
|
|
import { db } from "../../../common/database";
|
2022-08-26 16:19:39 +05:00
|
|
|
import {
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
ToastEvent
|
|
|
|
|
} from "../../../services/event-manager";
|
|
|
|
|
import Navigation from "../../../services/navigation";
|
|
|
|
|
import SearchService from "../../../services/search";
|
|
|
|
|
import { useNotebookStore } from "../../../stores/use-notebook-store";
|
2022-08-29 16:19:17 +05:00
|
|
|
import { useSelectionStore } from "../../../stores/use-selection-store";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { useThemeStore } from "../../../stores/use-theme-store";
|
|
|
|
|
import { eOpenMoveNoteDialog } from "../../../utils/events";
|
|
|
|
|
import { Dialog } from "../../dialog";
|
|
|
|
|
import DialogHeader from "../../dialog/dialog-header";
|
|
|
|
|
import { presentDialog } from "../../dialog/functions";
|
|
|
|
|
import { Button } from "../../ui/button";
|
|
|
|
|
import SheetWrapper from "../../ui/sheet";
|
|
|
|
|
import Paragraph from "../../ui/typography/paragraph";
|
2023-02-09 15:29:30 +05:00
|
|
|
import { SelectionProvider } from "./context";
|
|
|
|
|
import { FilteredList } from "./filtered-list";
|
|
|
|
|
import { ListItem } from "./list-item";
|
|
|
|
|
|
2020-12-16 11:02:40 +05:00
|
|
|
const actionSheetRef = createRef();
|
2022-02-28 15:32:55 +05:00
|
|
|
const AddToNotebookSheet = () => {
|
2020-09-14 17:10:02 +05:00
|
|
|
const [visible, setVisible] = useState(false);
|
2020-12-14 15:57:50 +05:00
|
|
|
const [note, setNote] = useState(null);
|
2021-02-15 11:09:01 +05:00
|
|
|
|
2020-12-16 09:31:20 +05:00
|
|
|
function open(note) {
|
|
|
|
|
setNote(note);
|
2020-09-14 16:45:41 +05:00
|
|
|
setVisible(true);
|
2020-12-29 11:24:34 +05:00
|
|
|
actionSheetRef.current?.setModalVisible(true);
|
2020-09-14 16:45:41 +05:00
|
|
|
}
|
2020-12-16 09:31:20 +05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eOpenMoveNoteDialog, open);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eOpenMoveNoteDialog, open);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const _onClose = () => {
|
2020-09-14 16:45:41 +05:00
|
|
|
setVisible(false);
|
2020-12-14 15:57:50 +05:00
|
|
|
setNote(null);
|
2022-04-24 05:59:14 +05:00
|
|
|
Navigation.queueRoutesForUpdate(
|
2022-08-26 16:19:39 +05:00
|
|
|
"Notes",
|
|
|
|
|
"Favorites",
|
|
|
|
|
"ColoredNotes",
|
|
|
|
|
"TaggedNotes",
|
|
|
|
|
"TopicNotes",
|
|
|
|
|
"Notebooks",
|
|
|
|
|
"Notebook"
|
2022-04-24 05:59:14 +05:00
|
|
|
);
|
2020-09-14 16:45:41 +05:00
|
|
|
};
|
2020-01-18 18:13:34 +05:00
|
|
|
|
2020-12-16 09:31:20 +05:00
|
|
|
return !visible ? null : (
|
2021-12-25 11:16:33 +05:00
|
|
|
<SheetWrapper fwdRef={actionSheetRef} onClose={_onClose}>
|
2022-03-14 18:27:01 +05:00
|
|
|
<MoveNoteComponent note={note} />
|
2021-12-25 11:16:33 +05:00
|
|
|
</SheetWrapper>
|
2020-12-16 09:31:20 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-28 15:32:55 +05:00
|
|
|
export default AddToNotebookSheet;
|
2020-12-16 09:31:20 +05:00
|
|
|
|
2022-03-14 18:27:01 +05:00
|
|
|
const MoveNoteComponent = ({ note }) => {
|
2022-08-26 16:19:39 +05:00
|
|
|
const colors = useThemeStore((state) => state.colors);
|
2023-02-09 15:29:30 +05:00
|
|
|
const [multiSelect, setMultiSelect] = useState(false);
|
2022-08-26 16:19:39 +05:00
|
|
|
const notebooks = useNotebookStore((state) =>
|
|
|
|
|
state.notebooks.filter((n) => n?.type === "notebook")
|
|
|
|
|
);
|
2023-02-09 15:29:30 +05:00
|
|
|
const [edited, setEdited] = useState(false);
|
2022-08-26 16:19:39 +05:00
|
|
|
const selectedItemsList = useSelectionStore(
|
|
|
|
|
(state) => state.selectedItemsList
|
|
|
|
|
);
|
|
|
|
|
const setNotebooks = useNotebookStore((state) => state.setNotebooks);
|
2023-02-09 15:29:30 +05:00
|
|
|
const [itemState, setItemState] = useState({});
|
|
|
|
|
|
|
|
|
|
const onAddNotebook = async (title) => {
|
|
|
|
|
if (!title || title.trim().length === 0) {
|
|
|
|
|
ToastEvent.show({
|
2022-08-26 16:19:39 +05:00
|
|
|
heading: "Notebook title is required",
|
|
|
|
|
type: "error",
|
|
|
|
|
context: "local"
|
2021-02-20 15:03:02 +05:00
|
|
|
});
|
2023-02-09 15:29:30 +05:00
|
|
|
return false;
|
|
|
|
|
}
|
2020-01-18 18:13:34 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
await db.notebooks.add({
|
|
|
|
|
title: title,
|
2020-12-16 09:31:20 +05:00
|
|
|
description: null,
|
2020-09-14 16:45:41 +05:00
|
|
|
topics: [],
|
2021-12-27 18:09:00 +05:00
|
|
|
id: null
|
2020-01-18 18:13:34 +05:00
|
|
|
});
|
2021-06-05 21:10:20 +05:00
|
|
|
setNotebooks();
|
2023-02-09 15:29:30 +05:00
|
|
|
return true;
|
2020-09-14 16:45:41 +05:00
|
|
|
};
|
2020-01-18 18:13:34 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
const openAddTopicDialog = (item) => {
|
|
|
|
|
presentDialog({
|
|
|
|
|
context: "move_note",
|
|
|
|
|
input: true,
|
|
|
|
|
inputPlaceholder: "Enter title",
|
|
|
|
|
title: "New topic",
|
|
|
|
|
paragraph: "Add a new topic in " + item.title,
|
|
|
|
|
positiveText: "Add",
|
|
|
|
|
positivePress: (value) => {
|
|
|
|
|
return onAddTopic(value, item);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-09-14 16:45:41 +05:00
|
|
|
};
|
|
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
const onAddTopic = useCallback(
|
|
|
|
|
async (value, item) => {
|
|
|
|
|
if (!value || value.trim().length === 0) {
|
|
|
|
|
ToastEvent.show({
|
|
|
|
|
heading: "Topic title is required",
|
|
|
|
|
type: "error",
|
|
|
|
|
context: "local"
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-16 11:08:58 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
await db.notebooks.notebook(item.id).topics.add(value);
|
|
|
|
|
setNotebooks();
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[setNotebooks]
|
|
|
|
|
);
|
2022-04-24 05:59:14 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
const getSelectedNotesCountInItem = React.useCallback(
|
|
|
|
|
(item) => {
|
|
|
|
|
switch (item.type) {
|
|
|
|
|
case "notebook": {
|
|
|
|
|
const noteIds = [];
|
|
|
|
|
for (let topic of item.topics) {
|
|
|
|
|
noteIds.push(...(db.notes?.topicReferences.get(topic.id) || []));
|
|
|
|
|
}
|
|
|
|
|
let count = 0;
|
|
|
|
|
selectedItemsList.forEach((item) =>
|
|
|
|
|
noteIds.indexOf(item.id) > -1 ? count++ : undefined
|
|
|
|
|
);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
case "topic": {
|
|
|
|
|
const noteIds = db.notes?.topicReferences.get(item.id);
|
|
|
|
|
let count = 0;
|
|
|
|
|
selectedItemsList.forEach((item) =>
|
|
|
|
|
noteIds.indexOf(item.id) > -1 ? count++ : undefined
|
|
|
|
|
);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[selectedItemsList]
|
|
|
|
|
);
|
2020-12-16 11:08:58 +05:00
|
|
|
|
2021-02-26 14:29:29 +05:00
|
|
|
useEffect(() => {
|
2023-02-09 15:29:30 +05:00
|
|
|
resetItemState();
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const resetItemState = useCallback(
|
|
|
|
|
(state) => {
|
|
|
|
|
setItemState(() => {
|
|
|
|
|
const itemState = {};
|
|
|
|
|
const notebooks = db.notebooks.all;
|
|
|
|
|
for (let notebook of notebooks) {
|
|
|
|
|
itemState[notebook.id] = state
|
|
|
|
|
? state
|
|
|
|
|
: areAllSelectedItemsInAllTopics(notebook, selectedItemsList) &&
|
|
|
|
|
getSelectedNotesCountInItem(notebook, selectedItemsList) > 0
|
|
|
|
|
? "selected"
|
|
|
|
|
: getSelectedNotesCountInItem(notebook, selectedItemsList) > 0
|
|
|
|
|
? "intermediate"
|
|
|
|
|
: "deselected";
|
|
|
|
|
if (itemState[notebook.id] === "selected") {
|
|
|
|
|
contextValue.select(notebook);
|
|
|
|
|
}
|
|
|
|
|
for (let topic of notebook.topics) {
|
|
|
|
|
itemState[topic.id] = state
|
|
|
|
|
? state
|
|
|
|
|
: areAllSelectedItemsInTopic(topic, selectedItemsList) &&
|
|
|
|
|
getSelectedNotesCountInItem(topic, selectedItemsList)
|
|
|
|
|
? "selected"
|
|
|
|
|
: getSelectedNotesCountInItem(topic, selectedItemsList) > 0
|
|
|
|
|
? "intermediate"
|
|
|
|
|
: "deselected";
|
|
|
|
|
if (itemState[topic.id] === "selected") {
|
|
|
|
|
contextValue.select(topic);
|
2022-03-14 18:27:01 +05:00
|
|
|
}
|
2021-07-17 20:40:09 +05:00
|
|
|
}
|
2021-02-26 14:29:29 +05:00
|
|
|
}
|
2023-02-09 15:29:30 +05:00
|
|
|
return itemState;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[contextValue, getSelectedNotesCountInItem, selectedItemsList]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const getItemsForItem = (item) => {
|
|
|
|
|
switch (item.type) {
|
|
|
|
|
case "notebook":
|
|
|
|
|
return item.topics?.filter((t) => t.type === "topic");
|
2021-02-26 14:29:29 +05:00
|
|
|
}
|
2023-02-09 15:29:30 +05:00
|
|
|
};
|
2022-08-31 13:03:22 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
function areAllSelectedItemsInAllTopics(notebook, items) {
|
|
|
|
|
return items.every((item) => {
|
|
|
|
|
return notebook.topics.every((topic) => {
|
|
|
|
|
return db.notes.topicReferences.get(topic.id).indexOf(item.id) > -1;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-27 18:09:00 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
function areAllSelectedItemsInTopic(topic, items) {
|
|
|
|
|
return items.every((item) => {
|
|
|
|
|
return db.notes.topicReferences.get(topic.id).indexOf(item.id) > -1;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateItemState = useCallback(function (item, state) {
|
|
|
|
|
setItemState((itemState) => {
|
|
|
|
|
const mergeState = {
|
|
|
|
|
[item.id]: state
|
|
|
|
|
};
|
2023-02-13 12:11:08 +05:00
|
|
|
const notebooks = db.notebooks.all;
|
|
|
|
|
const notebook =
|
|
|
|
|
item.type === "notebook"
|
|
|
|
|
? item
|
|
|
|
|
: notebooks.find((n) => n.id === item.notebookId);
|
|
|
|
|
const intermediate = notebook.topics.some((topic) => {
|
|
|
|
|
return topic.id === item.id
|
|
|
|
|
? state === "selected"
|
|
|
|
|
: itemState[topic.id] === "selected";
|
|
|
|
|
});
|
|
|
|
|
if (intermediate) mergeState[notebook.id] = "intermediate";
|
|
|
|
|
const selected = notebook.topics.every((topic) => {
|
|
|
|
|
return topic.id === item.id
|
|
|
|
|
? state === "selected"
|
|
|
|
|
: itemState[topic.id] === "selected";
|
|
|
|
|
});
|
|
|
|
|
if (selected) mergeState[notebook.id] = "selected";
|
|
|
|
|
if (!selected && !intermediate) mergeState[notebook.id] = "deselected";
|
2023-02-09 15:29:30 +05:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...itemState,
|
|
|
|
|
...mergeState
|
|
|
|
|
};
|
2021-12-27 18:09:00 +05:00
|
|
|
});
|
2023-02-09 15:29:30 +05:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const contextValue = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
enabled: multiSelect,
|
|
|
|
|
toggleSelection: (item) => {
|
|
|
|
|
setItemState((itemState) => {
|
|
|
|
|
if (itemState[item.id] === "selected") {
|
|
|
|
|
updateItemState(item, "deselected");
|
|
|
|
|
} else {
|
|
|
|
|
updateItemState(item, "selected");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemState;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
setMultiSelect: setMultiSelect,
|
|
|
|
|
deselect: (item) => {
|
|
|
|
|
updateItemState(item, "deselected");
|
|
|
|
|
},
|
|
|
|
|
select: (item) => {
|
|
|
|
|
updateItemState(item, "selected");
|
|
|
|
|
},
|
|
|
|
|
deselectAll: (state) => {
|
|
|
|
|
resetItemState(state);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
[multiSelect, resetItemState, updateItemState]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const getItemFromId = (id) => {
|
|
|
|
|
for (const nb of notebooks) {
|
|
|
|
|
if (nb.id === id) return nb;
|
|
|
|
|
for (const tp of nb.topics) {
|
|
|
|
|
if (tp.id === id) return tp;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-27 18:09:00 +05:00
|
|
|
};
|
2021-02-26 14:29:29 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
const onSave = async () => {
|
|
|
|
|
for (const id in itemState) {
|
|
|
|
|
const item = getItemFromId(id);
|
|
|
|
|
if (item.type === "notebook") continue;
|
|
|
|
|
const noteIds = selectedItemsList.map((n) => n.id);
|
|
|
|
|
if (itemState[id] === "selected") {
|
|
|
|
|
await db.notes.addToNotebook(
|
|
|
|
|
{
|
|
|
|
|
topic: item.id,
|
|
|
|
|
id: item.notebookId,
|
|
|
|
|
rebuildCache: true
|
|
|
|
|
},
|
|
|
|
|
...noteIds
|
|
|
|
|
);
|
|
|
|
|
} else if (itemState[id] === "deselected") {
|
|
|
|
|
await db.notes.removeFromNotebook(
|
|
|
|
|
{
|
|
|
|
|
id: item.notebookId,
|
|
|
|
|
topic: item.id,
|
|
|
|
|
rebuildCache: true
|
|
|
|
|
},
|
|
|
|
|
...noteIds
|
|
|
|
|
);
|
2022-03-14 18:27:01 +05:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-09 15:29:30 +05:00
|
|
|
Navigation.queueRoutesForUpdate(
|
|
|
|
|
"Notes",
|
|
|
|
|
"Favorites",
|
|
|
|
|
"ColoredNotes",
|
|
|
|
|
"TaggedNotes",
|
|
|
|
|
"TopicNotes"
|
|
|
|
|
);
|
|
|
|
|
setNotebooks();
|
|
|
|
|
SearchService.updateAndSearch();
|
|
|
|
|
actionSheetRef.current?.hide();
|
2022-03-14 18:27:01 +05:00
|
|
|
};
|
|
|
|
|
|
2020-12-16 09:31:20 +05:00
|
|
|
return (
|
|
|
|
|
<>
|
2021-12-27 18:09:00 +05:00
|
|
|
<Dialog context="move_note" />
|
2020-12-16 09:31:20 +05:00
|
|
|
<View>
|
|
|
|
|
<TouchableOpacity
|
2020-01-18 18:13:34 +05:00
|
|
|
style={{
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
position: "absolute"
|
2020-12-16 09:31:20 +05:00
|
|
|
}}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
Keyboard.dismiss();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12,
|
2023-02-09 15:29:30 +05:00
|
|
|
justifyContent: "space-between",
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
2023-02-09 15:29:30 +05:00
|
|
|
alignItems: "flex-start"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2020-12-16 09:31:20 +05:00
|
|
|
<DialogHeader
|
2023-02-09 15:29:30 +05:00
|
|
|
style={{
|
|
|
|
|
minHeight: 10,
|
|
|
|
|
flexShrink: 1
|
|
|
|
|
}}
|
|
|
|
|
title="Select notebooks"
|
|
|
|
|
paragraph={
|
|
|
|
|
!multiSelect
|
|
|
|
|
? "Long press to enable multi-select."
|
|
|
|
|
: "Select topics you want to add note(s) to."
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
height={35}
|
|
|
|
|
style={{
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
paddingHorizontal: 24,
|
|
|
|
|
alignSelf: "flex-start"
|
|
|
|
|
}}
|
|
|
|
|
title="Save"
|
|
|
|
|
type={"accent"}
|
|
|
|
|
onPress={onSave}
|
2020-11-23 15:57:31 +05:00
|
|
|
/>
|
2020-12-16 09:31:20 +05:00
|
|
|
</View>
|
2020-11-23 15:57:31 +05:00
|
|
|
|
2023-02-09 15:29:30 +05:00
|
|
|
{multiSelect ? (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
title="Reset selection"
|
|
|
|
|
height={30}
|
2020-12-29 11:24:34 +05:00
|
|
|
style={{
|
2023-02-09 15:29:30 +05:00
|
|
|
alignSelf: "flex-start",
|
|
|
|
|
paddingHorizontal: 0
|
2020-12-29 11:24:34 +05:00
|
|
|
}}
|
2023-02-09 15:29:30 +05:00
|
|
|
onPress={() => {
|
|
|
|
|
resetItemState();
|
|
|
|
|
setMultiSelect(false);
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
2023-02-09 15:29:30 +05:00
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<SelectionProvider value={contextValue}>
|
|
|
|
|
<FilteredList
|
|
|
|
|
onMomentumScrollEnd={() => {
|
|
|
|
|
actionSheetRef.current?.handleChildScrollEnd();
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingHorizontal: 12
|
|
|
|
|
}}
|
|
|
|
|
ListEmptyComponent={
|
|
|
|
|
notebooks.length > 0 ? null : (
|
2020-09-14 16:45:41 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
2023-02-09 15:29:30 +05:00
|
|
|
height: "100%",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2023-02-09 15:29:30 +05:00
|
|
|
<Icon name="book-outline" color={colors.icon} size={100} />
|
|
|
|
|
<Paragraph style={{ marginBottom: 10 }}>
|
|
|
|
|
You do not have any notebooks.
|
|
|
|
|
</Paragraph>
|
2020-11-23 15:57:31 +05:00
|
|
|
</View>
|
2023-02-09 15:29:30 +05:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
data={notebooks}
|
|
|
|
|
hasHeaderSearch={true}
|
|
|
|
|
renderItem={({ item, index }) => (
|
|
|
|
|
<ListItem
|
|
|
|
|
item={item}
|
|
|
|
|
key={item.id}
|
|
|
|
|
index={index}
|
|
|
|
|
intermediate={itemState[item.id] === "intermediate"}
|
|
|
|
|
removed={
|
|
|
|
|
itemState[item.id] === "deselected" &&
|
|
|
|
|
getSelectedNotesCountInItem(item) > 0
|
|
|
|
|
}
|
|
|
|
|
isSelected={itemState[item.id] === "selected"}
|
|
|
|
|
infoText={
|
|
|
|
|
<>
|
|
|
|
|
{item.topics.length === 1
|
|
|
|
|
? item.topics.length + " topic"
|
|
|
|
|
: item.topics.length + " topics"}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
getListItems={getItemsForItem}
|
|
|
|
|
getSublistItemProps={(topic) => ({
|
|
|
|
|
selected: itemState[topic.id] === "selected",
|
|
|
|
|
intermediate: itemState[topic.id] === "intermediate",
|
|
|
|
|
isSelected: itemState[topic.id] === "selected",
|
|
|
|
|
removed:
|
|
|
|
|
itemState[topic.id] === "deselected" &&
|
|
|
|
|
getSelectedNotesCountInItem(topic) > 0,
|
|
|
|
|
style: {
|
|
|
|
|
marginBottom: 0,
|
|
|
|
|
height: 40
|
|
|
|
|
},
|
|
|
|
|
onPress: (item) => {
|
|
|
|
|
const currentState = itemState[item.id];
|
|
|
|
|
if (currentState !== "selected") {
|
|
|
|
|
resetItemState("deselected");
|
|
|
|
|
contextValue.select(item);
|
|
|
|
|
updateItemState(
|
|
|
|
|
notebooks.find((n) => n.id === item.notebookId),
|
|
|
|
|
"intermediate"
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
contextValue.deselect(item);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
key: item.id,
|
|
|
|
|
type: "transparent"
|
|
|
|
|
})}
|
|
|
|
|
icon={(expanded) => ({
|
|
|
|
|
name: expanded ? "chevron-up" : "chevron-down",
|
|
|
|
|
color: expanded ? colors.accent : colors.pri
|
|
|
|
|
})}
|
|
|
|
|
onScrollEnd={() => {
|
|
|
|
|
actionSheetRef.current?.handleChildScrollEnd();
|
|
|
|
|
}}
|
|
|
|
|
hasSubList={true}
|
|
|
|
|
hasHeaderSearch={false}
|
|
|
|
|
type="grayBg"
|
|
|
|
|
sublistItemType="topic"
|
|
|
|
|
onAddItem={(title) => {
|
|
|
|
|
return onAddTopic(title, item);
|
|
|
|
|
}}
|
|
|
|
|
onAddSublistItem={(item) => {
|
|
|
|
|
openAddTopicDialog(item);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
itemType="notebook"
|
|
|
|
|
onAddItem={async (title) => {
|
|
|
|
|
return await onAddNotebook(title);
|
|
|
|
|
}}
|
|
|
|
|
ListFooterComponent={
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
height: 200
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</SelectionProvider>
|
2020-12-16 09:31:20 +05:00
|
|
|
</View>
|
|
|
|
|
</>
|
2020-09-14 16:45:41 +05:00
|
|
|
);
|
|
|
|
|
};
|