From a0edf00caa3bb8cd3e61821ce591ff0162635396 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 5 Nov 2025 23:17:15 +0200 Subject: [PATCH] feat(collections/calendar): context menu option to delete event --- .../src/translations/en/translation.json | 3 ++ .../collections/calendar/context_menu.ts | 28 +++++++++++++++++++ .../widgets/collections/calendar/index.tsx | 10 +++++-- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 apps/client/src/widgets/collections/calendar/context_menu.ts diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index f89e42f47..22857153a 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -2037,6 +2037,9 @@ "start-presentation": "Start presentation", "slide-overview": "Toggle an overview of the slides" }, + "calendar_view": { + "delete_note": "Delete note..." + }, "command_palette": { "tree-action-name": "Tree: {{name}}", "export_note_title": "Export Note", diff --git a/apps/client/src/widgets/collections/calendar/context_menu.ts b/apps/client/src/widgets/collections/calendar/context_menu.ts new file mode 100644 index 000000000..7eddbed3c --- /dev/null +++ b/apps/client/src/widgets/collections/calendar/context_menu.ts @@ -0,0 +1,28 @@ +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 { t } from "../../../services/i18n"; + +export function openCalendarContextMenu(e: ContextMenuEvent, noteId: string, parentNote: FNote) { + e.preventDefault(); + e.stopPropagation(); + + contextMenu.show({ + x: e.pageX, + y: e.pageY, + items: [ + ...link_context_menu.getItems(), + { kind: "separator" }, + { + title: t("calendar_view.delete_note"), + uiIcon: "bx bx-trash", + handler: async () => { + const branchId = parentNote.childToBranch[noteId]; + await branches.deleteNotes([ branchId ], false, false); + } + } + ], + selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, noteId), + }) +} diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx index 3c3925bae..c1b288e27 100644 --- a/apps/client/src/widgets/collections/calendar/index.tsx +++ b/apps/client/src/widgets/collections/calendar/index.tsx @@ -20,6 +20,7 @@ import Button, { ButtonGroup } from "../../react/Button"; import ActionButton from "../../react/ActionButton"; import { RefObject } from "preact"; import TouchBar, { TouchBarButton, TouchBarLabel, TouchBarSegmentedControl, TouchBarSpacer } from "../../react/TouchBar"; +import { openCalendarContextMenu } from "./context_menu"; interface CalendarViewData { @@ -106,7 +107,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps { const { iconClass, promotedAttributes } = e.event.extendedProps; @@ -302,6 +303,11 @@ function useEventDisplayCustomization() { } $(mainContainer ?? e.el).append($(promotedAttributesHtml)); } + + e.el.addEventListener("contextmenu", (contextMenuEvent) => { + const noteId = e.event.extendedProps.noteId; + openCalendarContextMenu(contextMenuEvent, noteId, parentNote); + }); }, []); return { eventDidMount }; }