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

This commit is contained in:
Adorian Doran 2025-12-01 13:29:28 +02:00
parent e69b5988ec
commit 90b5282b39
4 changed files with 34 additions and 31 deletions

View File

@ -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")
}
}
}
}

View File

@ -2,9 +2,9 @@ import FNote from "../../../entities/fnote";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker"; import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker";
import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu"; import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
import link_context_menu from "../../../menus/link_context_menu"; import link_context_menu from "../../../menus/link_context_menu";
import attributes from "../../../services/attributes";
import branches from "../../../services/branches"; import branches from "../../../services/branches";
import dialog from "../../../services/dialog"; import dialog from "../../../services/dialog";
import { getArchiveMenuItem } from "../../../menus/context_menu_utils";
import { t } from "../../../services/i18n"; import { t } from "../../../services/i18n";
import Api from "./api"; import Api from "./api";
@ -52,7 +52,6 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
handler: () => api.changeColumn(note.noteId, columnToMoveTo) handler: () => api.changeColumn(note.noteId, columnToMoveTo)
})), })),
}, },
getArchiveMenuItem(note),
{ kind: "separator" }, { kind: "separator" },
{ {
title: t("board_view.insert-above"), 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") handler: () => api.insertRowAtPosition(column, branchId, "after")
}, },
{ kind: "separator" }, { kind: "separator" },
getArchiveMenuItem(note),
{ {
title: t("board_view.remove-from-board"), title: t("board_view.remove-from-board"),
uiIcon: "bx bx-task-x", 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")
}
}
}
}

View File

@ -3,11 +3,10 @@ import FNote from "../../../entities/fnote";
import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu"; import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
import link_context_menu from "../../../menus/link_context_menu"; import link_context_menu from "../../../menus/link_context_menu";
import branches from "../../../services/branches"; import branches from "../../../services/branches";
import froca from "../../../services/froca"; import { getArchiveMenuItem } from "../../../menus/context_menu_utils";
import { note } from "mermaid/dist/rendering-util/rendering-elements/shapes/note.js";
import { t } from "../../../services/i18n"; 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.preventDefault();
e.stopPropagation(); e.stopPropagation();
@ -17,15 +16,13 @@ export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, par
items: [ items: [
...link_context_menu.getItems(), ...link_context_menu.getItems(),
{ kind: "separator" }, { kind: "separator" },
getArchiveMenuItem(note),
{ {
title: t("calendar_view.delete_note"), title: t("calendar_view.delete_note"),
uiIcon: "bx bx-trash", uiIcon: "bx bx-trash",
handler: async () => { handler: async () => {
const noteToDelete = await froca.getNote(noteId);
if (!noteToDelete) return;
let branchIdToDelete: string | null = null; let branchIdToDelete: string | null = null;
for (const parentBranch of noteToDelete.getParentBranches()) { for (const parentBranch of note.getParentBranches()) {
const parentNote = await parentBranch.getNote(); const parentNote = await parentBranch.getNote();
if (parentNote?.hasAncestor(parentNote.noteId)) { if (parentNote?.hasAncestor(parentNote.noteId)) {
branchIdToDelete = parentBranch.branchId; branchIdToDelete = parentBranch.branchId;
@ -40,9 +37,9 @@ export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, par
{ kind: "separator" }, { kind: "separator" },
{ {
kind: "custom", 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),
}) })
} }

View File

@ -307,9 +307,11 @@ function useEventDisplayCustomization(parentNote: FNote) {
$(mainContainer ?? e.el).append($(promotedAttributesHtml)); $(mainContainer ?? e.el).append($(promotedAttributesHtml));
} }
e.el.addEventListener("contextmenu", (contextMenuEvent) => { e.el.addEventListener("contextmenu", async (contextMenuEvent) => {
const noteId = e.event.extendedProps.noteId; const note = await froca.getNote(e.event.extendedProps.noteId);
openCalendarContextMenu(contextMenuEvent, noteId, parentNote); if (!note) return;
openCalendarContextMenu(contextMenuEvent, note, parentNote);
}); });
}, []); }, []);
return { eventDidMount }; return { eventDidMount };