Skip to content

Build your personal knowledge base with Trilium Notes

refactor(react/collections/calendar): add back clicking on date notes

Elian Doran85e5f4d2c021
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 1a4114251d..be3607f96a 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -15,6 +15,9 @@ import { t } from "../../../services/i18n";
import { buildEvents, buildEventsForCalendar } from "./event_builder";
import { changeEvent, newEvent } from "./api";
import froca from "../../../services/froca";
+import date_notes from "../../../services/date_notes";
+import appContext from "../../../components/app_context";
+import { DateClickArg } from "@fullcalendar/interaction";
interface CalendarViewData {
@@ -92,6 +95,16 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
changeEvent(note, { startDate, endDate, startTime, endTime });
}, []);
+ // Called upon when clicking the day number in the calendar, opens or creates the day note but only if in a calendar root.
+ const onDateClick = useCallback(async (e: DateClickArg) => {
+ if (!isCalendarRoot) return;
+
+ const eventNote = await date_notes.getDayNote(e.dateStr);
+ if (eventNote) {
+ appContext.triggerCommand("openInPopup", { noteIdOrPath: eventNote.noteId });
+ }
+ }, []);
+
return (plugins &&
<div className="calendar-view" ref={containerRef}>
<Calendar
@@ -112,6 +125,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
editable={isEditable} selectable={isEditable}
select={onCalendarSelection}
eventChange={onEventChange}
+ dateClick={onDateClick}
viewDidMount={({ view }) => {
if (initialView.current !== view.type) {
initialView.current = view.type;
diff --git a/apps/client/src/widgets/view_widgets/calendar_view.ts b/apps/client/src/widgets/view_widgets/calendar_view.ts
index 8448baf1aa..d2e8bcc8d0 100644
--- a/apps/client/src/widgets/view_widgets/calendar_view.ts
+++ b/apps/client/src/widgets/view_widgets/calendar_view.ts
@@ -86,18 +86,6 @@ export default class CalendarView extends ViewMode<{}> {
$(mainContainer ?? e.el).append($(promotedAttributesHtml));
}
},
- // Called upon when clicking the day number in the calendar, opens or creates the day note but only if in a calendar root.
- dateClick: async (e) => {
- if (!this.isCalendarRoot) {
- return;
- }
-
- const note = await date_notes.getDayNote(e.dateStr);
- if (note) {
- appContext.triggerCommand("openInPopup", { noteIdOrPath: note.noteId });
- appContext.triggerCommand("refreshNoteList", { noteId: this.parentNote.noteId });
- }
- },
datesSet: (e) => this.#onDatesSet(e),
});