Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style(calendar): shorten the occurrence title comments
Elian Dorane8e3ea23c1b7
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts b/apps/client/src/widgets/collections/calendar/event_builder.spec.tsindex dc1d558b83..9c8d257f0a 100644--- a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts+++ b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts@@ -478,7 +478,6 @@ describe("Recurrence", () => {expect(events[0]).toMatchObject({title: "John Smith",titleTemplate: "${title} (${years})",- // The date as the label holds it, the start time not yet worked into it.seriesStart: "1990-05-12"});});@@ -594,13 +593,8 @@ describe("Recurrence", () => {});});-/**- * The title a chip is drawn under, which a repeating event names once per occurrence: the calendar- * asks for it as each chip is drawn (see eventContent in index.tsx), the occurrence's own date in- * hand.- */describe("buildOccurrenceTitle", () => {- /** An event as FullCalendar hands it to a chip, this occurrence falling on the given day. */+ /** A FullCalendar event for the occurrence that starts on `start`. */function occurrence(titleTemplate: string | null, start: Date, seriesStart = "1990-05-12") {return { title: "John Smith", start, extendedProps: { titleTemplate, seriesStart } };}@@ -614,7 +608,6 @@ describe("buildOccurrenceTitle", () => {.toBe("John Smith (36)");expect(buildOccurrenceTitle(occurrence("${title} turns ${years}", new Date(2027, 4, 12)))).toBe("John Smith turns 37");- // The day the series itself starts on, which is where the count starts.expect(buildOccurrenceTitle(occurrence("${title} (${years})", new Date(1990, 4, 12)))).toBe("John Smith (0)");});diff --git a/apps/client/src/widgets/collections/calendar/event_builder.ts b/apps/client/src/widgets/collections/calendar/event_builder.tsindex e731c1a70f..0396e708ec 100644--- a/apps/client/src/widgets/collections/calendar/event_builder.ts+++ b/apps/client/src/widgets/collections/calendar/event_builder.ts@@ -130,8 +130,7 @@ export async function buildEvent(note: FNote, {const colorClass = note.getColorClass();const events: EventInput[] = [];- // The day the series starts on, read before the code below appends the start time and the- // exclusive end date. buildOccurrenceTitle() counts every occurrence from it.+ // Read before the start time is appended; `buildOccurrenceTitle()` counts years from it.const seriesStart = startDate;const titleTemplate = note.getLabelValue("calendar:titleTemplate");@@ -221,15 +220,9 @@ export async function buildEvent(note: FNote, {}/**- * Builds the title one occurrence of an event is drawn with: the note's `#calendar:titleTemplate`- * filled in for the day the occurrence falls on, or the plain title when the note has no template.- *- * Runs as the chip is drawn rather than in {@link buildEvent} because FullCalendar expands a- * `#recurrence` rule into occurrences itself: a repeating event is one {@link EventInput} with- * one title, so `${years}` — the whole years from `#startDate` to this occurrence — is only known- * here.- *- * A template {@link evaluateTemplate} rejects leaves the event with its plain title.+ * Returns the title of one occurrence: `#calendar:titleTemplate` evaluated for the occurrence's+ * date, or `title` when the template is missing or invalid. `eventContent` calls it per chip,+ * because the rrule plugin expands occurrences after `buildEvent()` runs.*/export function buildOccurrenceTitle({ title, start, extendedProps }: OccurrenceEvent) {const { titleTemplate, seriesStart } = extendedProps;@@ -237,8 +230,7 @@ export function buildOccurrenceTitle({ title, start, extendedProps }: Occurrencereturn title;}- // Both dates as plain days, without the time: a DST shift between them would otherwise take an- // hour off the span and round `years` down by a year.+ // Compares dates without times, so a DST shift between them cannot round `years` down.const occurrenceDay = formatDateToLocalISO(start);const seriesStartDay = dayjs(seriesStart.split("T")[0]);const occurrence = occurrenceDay ? dayjs(occurrenceDay) : seriesStartDay;@@ -256,23 +248,21 @@ export function buildOccurrenceTitle({ title, start, extendedProps }: Occurrence}}-/** The parts of a FullCalendar event {@link buildOccurrenceTitle} reads. */+/** The fields of a FullCalendar `EventApi` that `buildOccurrenceTitle()` reads. */interface OccurrenceEvent {title: string;- /** Where this occurrence starts; the template is filled in for that day. */start: Date | null;extendedProps: {titleTemplate?: string | null;- /** The `#startDate` the series is counted from, as {@link buildEvent} wrote it. */+ /** `#startDate` without the start time, as `buildEvent()` stores it. */seriesStart?: string | null;};}-/** Templates already reported. {@link buildOccurrenceTitle} runs for every chip the calendar- * draws, so a rejected template would otherwise be logged once per chip. */+/** Templates already logged, so an invalid one is reported once rather than once per chip. */const brokenTitleTemplates = new Set<string>();-/** Logs a template {@link evaluateTemplate} rejects, once per template. */+/** Logs a template that `evaluateTemplate()` rejects, once per template. */function reportBrokenTitleTemplate(template: string, error: unknown) {if (brokenTitleTemplates.has(template)) {return;diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex 606cf5c340..39d02cfa9f 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -731,8 +731,7 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u* theme hands out the very classes its time and title would have worn, so what is drawn here is* Forma's chip with an icon in it rather than something of ours standing in for one.*- * The title comes from buildOccurrenceTitle() rather than from the event, so a repeating event- * can title each of its occurrences differently.+ * `buildOccurrenceTitle()` gives each occurrence of a recurring event its own title.*/const eventContent = useCallback((e: EventDisplayInfo) => {const { iconClass, promotedAttributes } = e.event.extendedProps;