web: fix multiselect for notebook actions on note

This commit is contained in:
Abdullah Atta
2023-03-17 14:40:45 +05:00
committed by Abdullah Atta
parent efc678d3cd
commit da47ef159b
2 changed files with 22 additions and 11 deletions

View File

@@ -190,7 +190,8 @@ import {
mdiLightbulbOnOutline,
mdiNoteMultipleOutline,
mdiBookMultipleOutline,
mdiArrowTopRight
mdiArrowTopRight,
mdiBookmarkRemoveOutline
} from "@mdi/js";
import { useTheme } from "@emotion/react";
import { Theme } from "@notesnook/theme";
@@ -306,7 +307,8 @@ export const Check = createIcon(mdiCheck);
export const Cross = createIcon(mdiClose);
export const MoreVertical = createIcon(mdiDotsVertical);
export const Trash = createIcon(mdiTrashCanOutline);
export const TopicRemove = createIcon(mdiBookRemoveOutline);
export const TopicRemove = createIcon(mdiBookmarkRemoveOutline);
export const NotebookRemove = createIcon(mdiBookRemoveOutline);
export const Search = createIcon(mdiMagnify);
export const Menu = createIcon(mdiMenu);
export const Login = createIcon(mdiLoginVariant);

View File

@@ -533,27 +533,32 @@ function colorsToMenuItems() {
});
}
function notebooksMenuItems({ note }) {
function notebooksMenuItems({ items }) {
const noteIds = items.map((i) => i.id);
const menuItems = [];
menuItems.push({
key: "link-notebooks",
title: "Link to...",
icon: Icon.AddToNotebook,
onClick: async ({ items }) => {
await showMoveNoteDialog(items.map((i) => i.id));
onClick: async () => {
await showMoveNoteDialog(noteIds);
}
});
const notebooks = db.relations?.to(note, "notebook");
const notebooks = items
.map((note) => db.relations?.to(note, "notebook"))
.flat();
const topics = items.map((note) => note.notebooks || []).flat();
if (note && (note.notebooks?.length > 0 || notebooks?.length > 0)) {
if (topics?.length > 0 || notebooks?.length > 0) {
menuItems.push(
{
key: "remove-from-all-notebooks",
title: "Unlink from all",
icon: Icon.RemoveShortcutLink,
onClick: async () => {
await db.notes.removeFromAllNotebooks(note.id);
await db.notes.removeFromAllNotebooks(...noteIds);
store.refresh();
}
},
@@ -561,6 +566,8 @@ function notebooksMenuItems({ note }) {
);
notebooks?.forEach((notebook) => {
if (menuItems.find((item) => item.key === notebook.id)) return;
menuItems.push({
key: notebook.id,
title: notebook.title,
@@ -568,17 +575,19 @@ function notebooksMenuItems({ note }) {
checked: true,
tooltip: "Click to remove from this notebook",
onClick: async () => {
await db.notes.removeFromNotebook({ id: notebook.id }, note.id);
await db.notes.removeFromNotebook({ id: notebook.id }, ...noteIds);
store.refresh();
}
});
});
note.notebooks?.forEach((ref) => {
topics?.forEach((ref) => {
const notebook = db.notebooks?.notebook(ref.id);
if (!notebook) return;
for (const topicId of ref.topics) {
if (!notebook.topics.topic(topicId)) continue;
if (menuItems.find((item) => item.key === topicId)) continue;
const topic = notebook.topics.topic(topicId)._topic;
menuItems.push({
key: topicId,
@@ -589,7 +598,7 @@ function notebooksMenuItems({ note }) {
onClick: async () => {
await db.notes.removeFromNotebook(
{ id: ref.id, topic: topic.id },
note.id
...noteIds
);
store.refresh();
}