Skip to content

Build your personal knowledge base with Trilium Notes

Add validation, options menu and updated docs for calendar slot labels

BeatLinkbfb9bc28a493
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index dd8731ac49..7a8a74e6fe 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2102,7 +2102,9 @@
"slide-overview": "Toggle an overview of the slides"
},
"calendar_view": {
- "delete_note": "Delete note..."
+ "delete_note": "Delete note...",
+ "set_slot_duration": "Set slot duration",
+ "set_slot_label_interval": "Set slot label interval"
},
"ocr": {
"extracted_text": "Extracted Text (OCR)",
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 2b299cdc18..e0ca3a8c1c 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -3,7 +3,7 @@ import "./index.css";
import { Calendar as FullCalendar } from "@fullcalendar/core";
import { DateSelectArg, EventChangeArg, EventMountArg, EventSourceFuncArg, LocaleInput, PluginDef } from "@fullcalendar/core/index.js";
import { DateClickArg } from "@fullcalendar/interaction";
-import { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons";
+import { dayjs,DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons";
import { RefObject } from "preact";
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
@@ -40,6 +40,16 @@ interface CalendarViewData {
nextText: string;
}
+export const CALENDAR_SLOT_DURATIONS = {
+ "00:01:00": "1 Minute",
+ "00:05:00": "5 Minutes",
+ "00:10:00": "10 Minutes",
+ "00:20:00": "20 Minutes",
+ "00:30:00": "30 Minutes",
+ "01:00:00": "1 Hour"
+};
+
+
const CALENDAR_VIEWS = [
{
type: "timeGridDay",
@@ -80,7 +90,7 @@ const CALENDAR_VIEWS = [
const SUPPORTED_CALENDAR_VIEW_TYPE = CALENDAR_VIEWS.map(v => v.type);
-const DEFAULT_SLOT_DURATION = "00:30:00";
+const DEFAULT_SLOT_DURATION = "00:15:00";
const DEFAULT_SLOT_LABEL_INTERVAL = "01:00:00";
@@ -140,6 +150,19 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
const { eventDidMount } = useEventDisplayCustomization(note, parentComponent?.componentId);
const editingProps = useEditing(note, isEditable, isCalendarRoot, parentComponent?.componentId);
+ const isValidDuration = (str) => {
+ if (!/^(\d{2}):([0-5]\d):([0-5]\d)$/.test(str)) return false;
+
+ const [hours, minutes, seconds] = str.split(':').map(Number);
+ const d = dayjs.duration({ hours, minutes, seconds });
+
+ const totalMs = d.asMilliseconds();
+ const oneMinute = dayjs.duration(1, 'minute').asMilliseconds();
+ const twentyFourHours = dayjs.duration(24, 'hours').asMilliseconds();
+
+ return totalMs >= oneMinute && totalMs <= twentyFourHours;
+ };
+
// React to changes.
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
const api = calendarRef.current;
@@ -178,8 +201,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
firstDay={firstDayOfWeek ?? 0}
weekends={!hideWeekends}
weekNumbers={weekNumbers}
- slotDuration={slotDuration || DEFAULT_SLOT_DURATION}
- slotLabelInterval={slotLabelInterval || DEFAULT_SLOT_LABEL_INTERVAL}
+ slotDuration={isValidDuration(slotDuration) ? slotDuration : DEFAULT_SLOT_DURATION}
+ slotLabelInterval={isValidDuration(slotLabelInterval) ? slotLabelInterval : DEFAULT_SLOT_LABEL_INTERVAL}
height="90%"
nowIndicator
handleWindowResize={false}
diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
index b4a46a89bc..f63c56deaa 100644
--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx
+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
@@ -3,6 +3,7 @@ import { t } from "i18next";
import Component from "../../components/component";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
+import CALENDAR_SLOT_DURATION from "../collections/calendar";
import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, type MapLayer } from "../collections/geomap/map_layer";
import { ViewTypeOptions } from "../collections/interface";
import { DEFAULT_THEME, getPresentationThemes } from "../collections/presentation/themes";
@@ -59,7 +60,27 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
icon: "bx bx-hash",
type: "checkbox",
bindToLabel: "calendar:weekNumbers"
- }
+ },
+ {
+ label: t("calendar_view.set_slot_duration"),
+ icon: "bx bx-time",
+ type: "combobox",
+ bindToLabel: "calendar:slotDuration",
+ options: Object.entries(CALENDAR_SLOT_DURATION).map(([durationId, durationLabel]) => ({
+ value: durationId,
+ label: durationLabel
+ }))
+ },
+ {
+ label: t("calendar_view.set_slot_label_interval"),
+ icon: "bx bx-time",
+ type: "combobox",
+ bindToLabel: "calendar:slotLabelInterval",
+ options: Object.entries(CALENDAR_SLOT_DURATION).map(([durationId, durationLabel]) => ({
+ value: durationId,
+ label: durationLabel
+ }))
+ },
]
},
geoMap: {
diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.md
index 137107ca42..d3a7bd51ef 100644
--- a/docs/User Guide/User Guide/Collections/Calendar.md
+++ b/docs/User Guide/User Guide/Collections/Calendar.md
@@ -177,6 +177,108 @@ Also note that the recurrence label can be made promoted as with the start and e
> [!WARNING]
> If the recurrence string is not valid, a toast will be shown with the note ID and title of the note with the erroneous recurrence message. This note will not be added to the calendar
+
+## Slot Duration & Slot Label Interval
+
+Trilium's calendar view is powered by FullCalendar, which gives you fine-grained control over how the time grid looks and behaves for day and week views. Two labels you can use to configure these views are `#slotDuration` and `#slotLabelInterval`. Understanding what each one does — and how they interact — lets you tailor the calendar to match your workflow, whether you're scheduling in 15-minute increments or planning out your day in broad hourly blocks.
+
+### `slotDuration`
+
+Controls how tall each time slot is on the calendar — essentially the smallest unit of time the grid is divided into. A shorter duration means more rows and finer granularity; a longer one means fewer, chunkier rows. The default is one row every 15 minutes
+
+**Examples:**
+
+| Value | Result |
+|---|---|
+| `#slotDuration="00:15:00"` | One row every 15 minutes |
+| `#slotDuration="00:30:00"` | One row every 30 minutes |
+| `#slotDuration="01:00:00"` | One row every hour |
+
+
+### `slotLabelInterval`
+
+Controls how often a time label appears on the left-hand axis. This is independent of the slot size — you can have very small slots but only label every hour to keep the axis readable. The default is a time label shown every hour.
+
+**Examples:**
+
+| Value | Result |
+|---|---|
+| `slotLabelInterval="00:30:00"` | Show a time label every 30 minutes |
+| `slotLabelInterval="01:00:00"` | Show a time label every hour |
+
+
+
+### Useful combinations
+
+| `slotDuration` | `slotLabelInterval` | Result |
+|---|---|---|
+| `00:15:00` | `01:00:00` | Fine grid, clean axis — good for busy schedules |
+| `00:30:00` | `01:00:00` | Standard calendar feel |
+| `01:00:00` | `01:00:00` | Simple hourly grid — good for day planning |
+| `00:15:00` | `00:30:00` | Fine grid, labels every 30 min — balanced detail |
+
+### Format
+
+Both values use `HH:mm:ss` format. Hours can go up to `24` (`24:00:00`), while minutes and seconds must be between `00` and `59`. The minimum meaningful duration is 1 minute (`00:01:00`).
+
+### Examples
+
+#### `#slotDuration="00:05:00"` — `#slotLabelInterval="00:30:00"`
+
+Slots every 5 minutes, but only labelled every 30 minutes. Useful for very precise scheduling without a cluttered axis.
+
+| Axis | Time |
+|---|---|
+| **9:00** | 9:00 |
+| | 9:05 |
+| | 9:10 |
+| | 9:15 |
+| | 9:20 |
+| | 9:25 |
+| **9:30** | 9:30 |
+| | 9:35 |
+| | 9:40 |
+| | 9:45 |
+| | 9:50 |
+| | 9:55 |
+| **10:00** | 10:00 |
+| | 10:05 |
+| | 10:10 |
+| | 10:15 |
+| | 10:20 |
+| | 10:25 |
+| **10:30** | 10:30 |
+| | 10:35 |
+| | 10:40 |
+| | 10:45 |
+| | 10:50 |
+| | 10:55 |
+
+---
+
+#### `#slotDuration="00:15:00"` — `#slotLabelInterval="01:00:00"`
+
+Slots every 15 minutes, but only labelled on the hour. A good balance between granularity and readability.
+
+| Axis | Time |
+|---|---|
+| **9:00** | 9:00 |
+| | 9:15 |
+| | 9:30 |
+| | 9:45 |
+| **10:00** | 10:00 |
+| | 10:15 |
+| | 10:30 |
+| | 10:45 |
+| **11:00** | 11:00 |
+| | 11:15 |
+| | 11:30 |
+| | 11:45 |
+| **12:00** | 12:00 |
+| | 12:15 |
+| | 12:30 |
+
+
## Use-cases
### Using with the Journal / calendar