Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): offer only the places to open an event on a read-only calendar

Elian Doranb00470d0420c
diff --git a/apps/client/src/widgets/collections/calendar/context_menu.ts b/apps/client/src/widgets/collections/calendar/context_menu.ts
index a2d43036ab..0004673131 100644
--- a/apps/client/src/widgets/collections/calendar/context_menu.ts
+++ b/apps/client/src/widgets/collections/calendar/context_menu.ts
@@ -1,13 +1,17 @@
import type { CommandNames } from "../../../components/app_context";
import FNote from "../../../entities/fnote";
-import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
+import contextMenu, { ContextMenuEvent, type MenuItem } from "../../../menus/context_menu";
import { getArchiveMenuItems } from "../../../menus/context_menu_utils";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker";
import link_context_menu from "../../../menus/link_context_menu";
import branches from "../../../services/branches";
import { t } from "../../../services/i18n";
-export function openCalendarContextMenu(e: ContextMenuEvent, note: FNote, parentNote: FNote, componentId?: string) {
+/**
+ * Opens the menu of an event's note: the places to open it in, and on a calendar that is not
+ * read-only, archiving, deleting and coloring it.
+ */
+export function openCalendarContextMenu(e: ContextMenuEvent, note: FNote, parentNote: FNote, componentId?: string, isReadOnly = false) {
e.preventDefault();
e.stopPropagation();
@@ -16,31 +20,37 @@ export function openCalendarContextMenu(e: ContextMenuEvent, note: FNote, parent
y: e.pageY,
items: [
...link_context_menu.getItems(e),
- { kind: "separator" },
- ...getArchiveMenuItems<CommandNames>([ note ]),
- {
- title: t("calendar_view.delete_note"),
- uiIcon: "bx bx-trash",
- handler: async () => {
- let branchIdToDelete: string | null = null;
- for (const parentBranch of note.getParentBranches()) {
- const parentNote = await parentBranch.getNote();
- if (parentNote?.hasAncestor(parentNote.noteId)) {
- branchIdToDelete = parentBranch.branchId;
- }
- }
+ ...(isReadOnly ? [] : getEditingItems(note, componentId))
+ ],
+ selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, e, note.noteId),
+ });
+}
- if (branchIdToDelete) {
- await branches.deleteNotes([ branchIdToDelete ], false, false, componentId);
+function getEditingItems(note: FNote, componentId: string | undefined): MenuItem<CommandNames>[] {
+ return [
+ { kind: "separator" },
+ ...getArchiveMenuItems<CommandNames>([ note ]),
+ {
+ title: t("calendar_view.delete_note"),
+ uiIcon: "bx bx-trash",
+ handler: async () => {
+ let branchIdToDelete: string | null = null;
+ for (const parentBranch of note.getParentBranches()) {
+ const parentNote = await parentBranch.getNote();
+ if (parentNote?.hasAncestor(parentNote.noteId)) {
+ branchIdToDelete = parentBranch.branchId;
}
}
- },
- { kind: "separator" },
- {
- kind: "custom",
- componentFn: () => NoteColorPicker({note})
+
+ if (branchIdToDelete) {
+ await branches.deleteNotes([ branchIdToDelete ], false, false, componentId);
+ }
}
- ],
- selectMenuItemHandler: ({ command }) => link_context_menu.handleLinkContextMenuItem(command, e, note.noteId),
- });
+ },
+ { kind: "separator" },
+ {
+ kind: "custom",
+ componentFn: () => NoteColorPicker({note})
+ }
+ ];
}
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index f3ebfe56a8..4f78987221 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -172,7 +172,7 @@ export default function CalendarView({ note, noteIds, onOpenNote }: ViewModeProp
return true;
}, []);
- const { eventContent, eventDidMount, eventInnerClass } = useEventDisplayCustomization(note, parentComponent?.componentId, dismissSurface, !onOpenNote);
+ const { eventContent, eventDidMount, eventInnerClass } = useEventDisplayCustomization(note, parentComponent?.componentId, dismissSurface, isReadOnly);
const editingProps = useEditing(note, isEditable, isCalendarRoot, parentComponent?.componentId,
setSelection, effectiveSlotDuration);
@@ -674,8 +674,8 @@ function draftFromDateClick(e: DateClickInfo, slotDuration: string): EventDraft
function useEventDisplayCustomization(parentNote: FNote, componentId: string | undefined,
/** Puts away whatever surface stands over the calendar, answering whether there was one. */
dismissSurface: () => boolean,
- /** Whether a right click on an event opens its context menu, which a host opening notes itself has none of. */
- hasContextMenu: boolean) {
+ /** Whether the calendar is read-only, whose events' menu offers only the places to open them in. */
+ isReadOnly: boolean) {
/**
* The chip's own content, drawn so the note's icon can lead its title.
*
@@ -737,15 +737,13 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u
const note = await froca.getNote(e.event.extendedProps.noteId);
if (!note) return;
- openCalendarContextMenu(contextMenuEvent, note, parentNote, componentId);
+ openCalendarContextMenu(contextMenuEvent, note, parentNote, componentId, isReadOnly);
}
// A long press raises it on a phone, as a right-click does on a desktop; the tap itself now
// belongs to the event sheet, which offers what the menu offers and more (see onEventClick).
- if (hasContextMenu) {
- e.el.addEventListener("contextmenu", onContextMenu);
- }
- }, [ dismissSurface, hasContextMenu ]);
+ e.el.addEventListener("contextmenu", onContextMenu);
+ }, [ dismissSurface, isReadOnly ]);
return { eventContent, eventDidMount, eventInnerClass };
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
index 9569ab2bf0..d9a42d39dc 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
@@ -58,9 +58,10 @@
edge of the event and dragging the mouse around.</li>
</ul>
<p>On a <a href="#root/_help_CoFPLs3dRlXc">read-only</a> calendar, events can't
- be dragged, resized or created, and the button to pin the current date
- is hidden. Switching between the month, week and day views still works,
- but the choice isn't saved.</p>
+ be dragged, resized or created, their context menu only offers the places
+ to open them in, and the button to pin the current date is hidden. Switching
+ between the month, week and day views still works, but the choice isn't
+ saved.</p>
<h3>Popup view</h3>
<p>When an event is clicked, a popup will show near the event which contains
the following inforamtion:</p>
diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.md
index 1218c785ae..076bd0af95 100644
--- a/docs/User Guide/User Guide/Collections/Calendar.md
+++ b/docs/User Guide/User Guide/Collections/Calendar.md
@@ -42,7 +42,7 @@ After creating the event, it will show up on the calendar. To edit the content o
* Drag and drop an event on the calendar to move it to another day.
* The length of an event can be changed by placing the mouse to the right edge of the event and dragging the mouse around.
-On a [read-only](../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md) calendar, events can't be dragged, resized or created, and the button to pin the current date is hidden. Switching between the month, week and day views still works, but the choice isn't saved.
+On a [read-only](../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md) calendar, events can't be dragged, resized or created, their context menu only offers the places to open them in, and the button to pin the current date is hidden. Switching between the month, week and day views still works, but the choice isn't saved.
### Popup view