From d7409bec494f72295abf9abfae0ae4da35f0c258 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 23 Jan 2026 12:35:08 +0200 Subject: [PATCH] feat(calendar): don't trigger refresh on rename --- .../collections/calendar/event_builder.ts | 16 +++++++++------- .../src/widgets/collections/calendar/index.tsx | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 10 deletions(-) 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,10 +1,11 @@ import { EventInput, EventSourceFuncArg, EventSourceInput } from "@fullcalendar/core/index.js"; -import froca from "../../../services/froca"; -import { formatDateToLocalISO, getCustomisableLabel, getMonthsInDateRange, offsetDate } from "./utils"; -import FNote from "../../../entities/fnote"; -import server from "../../../services/server"; import clsx from "clsx"; +import FNote from "../../../entities/fnote"; +import froca from "../../../services/froca"; +import server from "../../../services/server"; +import { formatDateToLocalISO, getCustomisableLabel, getMonthsInDateRange, offsetDate } from "./utils"; + interface Event { startDate: string, endDate?: string | null, @@ -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 { - 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); } });