diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts index fdc5c20c6..7181261a8 100644 --- a/apps/client/src/menus/tree_context_menu.ts +++ b/apps/client/src/menus/tree_context_menu.ts @@ -14,6 +14,7 @@ import type FAttachment from "../entities/fattachment.js"; import type { SelectMenuItemEventListener } from "../components/events.js"; import utils from "../services/utils.js"; import attributes from "../services/attributes.js"; +import { executeBulkActions } from "../services/bulk_action.js"; // TODO: Deduplicate once client/server is well split. interface ConvertToAttachmentResponse { @@ -56,13 +57,17 @@ export default class TreeContextMenu implements SelectMenuItemEventListener node.data.noteId)); + if (note && !selectedNotes.includes(note)) selectedNotes.push(note); + const isArchived = selectedNotes.every(note => note.isArchived); + const canToggleArchived = !selectedNotes.some(note => note.isArchived !== isArchived); + const noSelectedNotes = selNodes.length === 0 || (selNodes.length === 1 && selNodes[0] === this.node); const notSearch = note?.type !== "search"; @@ -194,15 +199,30 @@ export default class TreeContextMenu implements SelectMenuItemEventListener { - if (!note) return; - if (!isArchived) { - attributes.addLabel(note.noteId, "archived"); + if (!selectedNotes.length) return; + + if (selectedNotes.length == 1) { + const note = selectedNotes[0]; + if (!isArchived) { + attributes.addLabel(note.noteId, "archived"); + } else { + attributes.removeOwnedLabelByName(note, "archived"); + } } else { - attributes.removeOwnedLabelByName(note, "archived"); + const noteIds = selectedNotes.map(note => note.noteId); + if (!isArchived) { + executeBulkActions(noteIds, [{ + name: "addLabel", labelName: "archived" + }]); + } else { + executeBulkActions(noteIds, [{ + name: "deleteLabel", labelName: "archived" + }]); + } } - }, - enabled: noSelectedNotes + } }, { title: `${t("tree-context-menu.delete")} `,