Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): don't trigger refresh on rename

Elian Dorand7409bec494f
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.ts b/apps/client/src/widgets/collections/calendar/event_builder.ts
index b2665b7883..f4611ccd7e 100644
--- a/apps/client/src/widgets/collections/calendar/event_builder.ts
+++ b/apps/client/src/widgets/collections/calendar/event_builder.ts
@@ -1,9 +1,10 @@
import { EventInput, EventSourceFuncArg, EventSourceInput } from "@fullcalendar/core/index.js";
-import froca from "../../../services/froca";
-import { formatDateToLocalISO, getCustomisableLabel, getMonthsInDateRange, offsetDate } from "./utils";
+import clsx from "clsx";
+
import FNote from "../../../entities/fnote";
+import froca from "../../../services/froca";
import server from "../../../services/server";
-import clsx from "clsx";
+import { formatDateToLocalISO, getCustomisableLabel, getMonthsInDateRange, offsetDate } from "./utils";
interface Event {
startDate: string,
@@ -105,7 +106,8 @@ export async function buildEvent(note: FNote, { startDate, endDate, startTime, e
endDate = (endTime ? `${endDate}T${endTime}:00` : endDate);
const eventData: EventInput = {
- title: title,
+ id: note.noteId,
+ title,
start: startDate,
url: `#${note.noteId}?popup`,
noteId: note.noteId,
@@ -148,12 +150,12 @@ async function parseCustomTitle(customTitlettributeName: string | null, note: FN
}
async function buildDisplayedAttributes(note: FNote, calendarDisplayedAttributes: string[]) {
- const filteredDisplayedAttributes = note.getAttributes().filter((attr): boolean => calendarDisplayedAttributes.includes(attr.name))
+ const filteredDisplayedAttributes = note.getAttributes().filter((attr): boolean => calendarDisplayedAttributes.includes(attr.name));
const result: Array<[string, string]> = [];
for (const attribute of filteredDisplayedAttributes) {
if (attribute.type === "label") result.push([attribute.name, attribute.value]);
- else result.push([attribute.name, (await attribute.getTargetNote())?.title || ""])
+ else result.push([attribute.name, (await attribute.getTargetNote())?.title || ""]);
}
return result;
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 0f14ee1552..7eb201b0c1 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -119,14 +119,25 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
// React to changes.
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- if (loadResults.getNoteIds().some(noteId => noteIds.includes(noteId)) // note title change.
- || loadResults.getAttributeRows(parentComponent?.componentId).some((a) => noteIds.includes(a.noteId ?? ""))) // subnote change.
- {
+ const api = calendarRef.current;
+ if (!api) return;
+
+ // Subnote attribute change.
+ if (loadResults.getAttributeRows(parentComponent?.componentId).some((a) => noteIds.includes(a.noteId ?? ""))) {
// Defer execution after the load results are processed so that the event builder has the updated data to work with.
setTimeout(() => {
console.log("Refresh");
calendarRef.current?.refetchEvents();
}, 0);
+ return; // early return since we'll refresh the events anyway
+ }
+
+ // Title change.
+ for (const noteId of loadResults.getNoteIds().filter(noteId => noteIds.includes(noteId))) {
+ const event = api.getEventById(noteId);
+ const note = froca.getNoteFromCache(noteId);
+ if (!event || !note) continue;
+ event.setProp("title", note.title);
}
});