Skip to content

Build your personal knowledge base with Trilium Notes

client/calendar collection: add "Archive note" command to the context menu

Adorian Doran90b5282b393b
diff --git a/apps/client/src/menus/context_menu_utils.ts b/apps/client/src/menus/context_menu_utils.ts
new file mode 100644
index 0000000000..9ac6f8b6ae
--- /dev/null
+++ b/apps/client/src/menus/context_menu_utils.ts
@@ -0,0 +1,21 @@
+import { t } from "../services/i18n"
+import attributes from "../services/attributes"
+import FNote from "../entities/fnote"
+
+export function getArchiveMenuItem(note: FNote) {
+ if (!note.isArchived) {
+ return {
+ title: t("board_view.archive-note"),
+ uiIcon: "bx bx-archive",
+ handler: () => attributes.addLabel(note.noteId, "archived")
+ }
+ } else {
+ return {
+ title: t("board_view.unarchive-note"),
+ uiIcon: "bx bx-archive-out",
+ handler: async () => {
+ attributes.removeOwnedLabelByName(note, "archived")
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index c834b4c8d4..ec869b6ed0 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -2,9 +2,9 @@ import FNote from "../../../entities/fnote";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker";
import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
import link_context_menu from "../../../menus/link_context_menu";
-import attributes from "../../../services/attributes";
import branches from "../../../services/branches";
import dialog from "../../../services/dialog";
+import { getArchiveMenuItem } from "../../../menus/context_menu_utils";
import { t } from "../../../services/i18n";
import Api from "./api";
@@ -52,7 +52,6 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
handler: () => api.changeColumn(note.noteId, columnToMoveTo)
})),
},
- getArchiveMenuItem(note),
{ kind: "separator" },
{
title: t("board_view.insert-above"),
@@ -65,6 +64,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
handler: () => api.insertRowAtPosition(column, branchId, "after")
},
{ kind: "separator" },
+ getArchiveMenuItem(note),
{
title: t("board_view.remove-from-board"),
uiIcon: "bx bx-task-x",
@@ -85,20 +85,3 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
});
}
-function getArchiveMenuItem(note: FNote) {
- if (!note.isArchived) {
- return {
- title: t("board_view.archive-note"),
- uiIcon: "bx bx-archive",
- handler: () => attributes.addLabel(note.noteId, "archived")
- }
- } else {
- return {
- title: t("board_view.unarchive-note"),
- uiIcon: "bx bx-archive-out",
- handler: async () => {
- attributes.removeOwnedLabelByName(note, "archived")
- }
- }
- }
-}
diff --git a/apps/client/src/widgets/collections/calendar/context_menu.ts b/apps/client/src/widgets/collections/calendar/context_menu.ts
index 0195d131c9..bb370a8f44 100644
--- a/apps/client/src/widgets/collections/calendar/context_menu.ts
+++ b/apps/client/src/widgets/collections/calendar/context_menu.ts
@@ -3,11 +3,10 @@ import FNote from "../../../entities/fnote";
import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
import link_context_menu from "../../../menus/link_context_menu";
import branches from "../../../services/branches";
-import froca from "../../../services/froca";
-import { note } from "mermaid/dist/rendering-util/rendering-elements/shapes/note.js";
+import { getArchiveMenuItem } from "../../../menus/context_menu_utils";
import { t } from "../../../services/i18n";
-export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, parentNote: FNote) {
+export function openCalendarContextMenu(e: ContextMenuEvent, note: FNote, parentNote: FNote) {
e.preventDefault();
e.stopPropagation();
@@ -17,15 +16,13 @@ export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, par
items: [
...link_context_menu.getItems(),
{ kind: "separator" },
+ getArchiveMenuItem(note),
{
title: t("calendar_view.delete_note"),
uiIcon: "bx bx-trash",
handler: async () => {
- const noteToDelete = await froca.getNote(noteId);
- if (!noteToDelete) return;
-
let branchIdToDelete: string | null = null;
- for (const parentBranch of noteToDelete.getParentBranches()) {
+ for (const parentBranch of note.getParentBranches()) {
const parentNote = await parentBranch.getNote();
if (parentNote?.hasAncestor(parentNote.noteId)) {
branchIdToDelete = parentBranch.branchId;
@@ -40,9 +37,9 @@ export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, par
{ kind: "separator" },
{
kind: "custom",
- componentFn: () => NoteColorPicker({note: noteId})
+ componentFn: () => NoteColorPicker({note: note})
}
],
- selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, noteId),
+ selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, note.noteId),
})
}
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 8bf5ce7f91..f7e61a5413 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -307,9 +307,11 @@ function useEventDisplayCustomization(parentNote: FNote) {
$(mainContainer ?? e.el).append($(promotedAttributesHtml));
}
- e.el.addEventListener("contextmenu", (contextMenuEvent) => {
- const noteId = e.event.extendedProps.noteId;
- openCalendarContextMenu(contextMenuEvent, noteId, parentNote);
+ e.el.addEventListener("contextmenu", async (contextMenuEvent) => {
+ const note = await froca.getNote(e.event.extendedProps.noteId);
+ if (!note) return;
+
+ openCalendarContextMenu(contextMenuEvent, note, parentNote);
});
}, []);
return { eventDidMount };