Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): add pin button to persist the calendar's initial date

Elian Doran86dee60f503a
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index fdc12282bb..c3b1fedacb 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -254,7 +254,7 @@
},
"onenote_import": {
"name": "Microsoft OneNote",
- "description": "From your OneNote account",
+ "description": "Connects to your account",
"connect_description": "Sign in with your Microsoft account to import your OneNote notebooks.",
"connect": "Sign in with Microsoft",
"connecting": "Waiting for sign-in to complete…",
@@ -792,7 +792,9 @@
"year_previous": "Previous year",
"year_next": "Next year",
"list": "List",
- "today": "Today"
+ "today": "Today",
+ "pin_date": "Pin the current date so the calendar always opens on this interval instead of today",
+ "unpin_date": "Unpin the date so the calendar opens on today's date again"
},
"close_pane_button": {
"close_this_pane": "Close this pane"
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index e291a66ad7..b51a4be6f1 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -26,7 +26,7 @@ import { changeEvent, newEvent } from "./api";
import Calendar from "./calendar";
import { openCalendarContextMenu } from "./context_menu";
import { buildEvents, buildEventsForCalendar } from "./event_builder";
-import { parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
+import { formatDateToLocalISO, parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
interface CalendarViewData {
@@ -199,6 +199,7 @@ function CalendarCollectionProperties({ note, calendarRef }: {
<span className="title">{title}</span>
<ActionButton icon="bx bx-chevron-right" text={currentViewData?.nextText ?? ""} onClick={() => calendarRef.current?.next()} />
<Button text={t("calendar.today")} onClick={() => calendarRef.current?.today()} />
+ <PinDateButton note={note} calendarRef={calendarRef} />
{isMobileLocal && <MobileCalendarViewSwitcher calendarRef={calendarRef} />}
</>}
rightChildren={<>
@@ -208,6 +209,31 @@ function CalendarCollectionProperties({ note, calendarRef }: {
);
}
+function PinDateButton({ note, calendarRef }: {
+ note: FNote;
+ calendarRef: RefObject<FullCalendar>;
+}) {
+ const [ initialDate, setInitialDate ] = useNoteLabel(note, "calendar:initialDate");
+ const isPinned = !!initialDate;
+
+ return (
+ <ActionButton
+ icon={isPinned ? "bx bxs-pin" : "bx bx-pin"}
+ text={isPinned ? t("calendar.unpin_date") : t("calendar.pin_date")}
+ onClick={() => {
+ if (isPinned) {
+ setInitialDate(null);
+ } else {
+ const date = formatDateToLocalISO(calendarRef.current?.view.currentStart);
+ if (date) {
+ setInitialDate(date);
+ }
+ }
+ }}
+ />
+ );
+}
+
function DesktopCalendarViewSwitcher({ calendarRef }: { calendarRef: RefObject<FullCalendar> }) {
const { viewType: currentViewType } = useOnDatesSet(calendarRef);