Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: use topicReferences to query if note exists in topic

ammarahm-edb5d884025956
diff --git a/apps/mobile/app/components/sheets/add-to/index.js b/apps/mobile/app/components/sheets/add-to/index.js
index a726687fe..eb97dd55c 100644
--- a/apps/mobile/app/components/sheets/add-to/index.js
+++ b/apps/mobile/app/components/sheets/add-to/index.js
@@ -194,6 +194,7 @@ const MoveNoteComponent = ({ note }) => {
? selectedItemsList.map((n) => n.id)
: [note?.id];
let ids = [];
+
let notebooks = db.notebooks.all;
for (let i = 0; i < notebooks.length; i++) {
if (notebooks[i].topics) {
@@ -201,7 +202,8 @@ const MoveNoteComponent = ({ note }) => {
let topic = notebooks[i].topics[t];
if (topic.type !== "topic") continue;
for (let id of notes) {
- if (topic.notes.indexOf(id) > -1) {
+ const noteIds = db.notes?.topicReferences.get(topic.id);
+ if (noteIds.indexOf(id) > -1) {
if (ids.indexOf(notebooks[i].id) === -1) {
ids.push(notebooks[i].id);
}
@@ -237,7 +239,8 @@ const MoveNoteComponent = ({ note }) => {
: [note?.id];
let count = 0;
for (let id of notes) {
- if (topic.notes.indexOf(id) > -1) {
+ const noteIds = db.notes?.topicReferences.get(topic.id);
+ if (noteIds.indexOf(id) > -1) {
count++;
}
}
diff --git a/apps/mobile/app/components/sheets/move-notes/movenote.tsx b/apps/mobile/app/components/sheets/move-notes/movenote.tsx
index 0bde3749f..98ff0ae9f 100644
--- a/apps/mobile/app/components/sheets/move-notes/movenote.tsx
+++ b/apps/mobile/app/components/sheets/move-notes/movenote.tsx
@@ -67,7 +67,12 @@ export const MoveNotes = ({
const [selectedNoteIds, setSelectedNoteIds] = useState<string[]>([]);
const [topic, setTopic] = useState(selectedTopic);
- notes = notes.filter((note) => topic?.notes.indexOf(note.id) === -1);
+
+ notes = notes.filter((note) => {
+ if (!topic) return [];
+ const noteIds = db.notes?.topicReferences.get(topic.id);
+ return noteIds.indexOf(note.id) === -1;
+ });
const select = (id: string) => {
const index = selectedNoteIds.indexOf(id);
diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.js
index 60d63b12d..3f21d290f 100644
--- a/apps/mobile/app/hooks/use-actions.js
+++ b/apps/mobile/app/hooks/use-actions.js
@@ -99,10 +99,9 @@ export const useActions = ({ close = () => null, item }) => {
const isNoteInTopic = () => {
const currentScreen = useNavigationStore.getState().currentScreen;
if (item.type !== "note" || currentScreen.name !== "TopicNotes") return;
- return db.notebooks
- .notebook(currentScreen.notebookId)
- .topics.topic(currentScreen.id)
- .has(item.id);
+ return (
+ db.notes?.topicReferences.get(currentScreen.id).indexOf(item.id) > -1
+ );
};
const onUpdate = useCallback(