From d6ccd106e6f08072d0751e1bedd4259f2969da44 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 5 Sep 2025 16:51:36 +0300 Subject: [PATCH] chore(react/collections/calendar): bring back locale --- .../widgets/collections/calendar/index.tsx | 36 ++++++++++++++++++- .../src/widgets/view_widgets/calendar_view.ts | 25 ------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx index 73bce3585..79cb2ac0e 100644 --- a/apps/client/src/widgets/collections/calendar/index.tsx +++ b/apps/client/src/widgets/collections/calendar/index.tsx @@ -1,9 +1,10 @@ -import { PluginDef } from "@fullcalendar/core/index.js"; +import { LocaleInput, PluginDef } from "@fullcalendar/core/index.js"; import { ViewModeProps } from "../interface"; import Calendar from "./calendar"; import { useEffect, useState } from "preact/hooks"; import "./index.css"; import { useNoteLabel, useNoteLabelBoolean, useTriliumOption, useTriliumOptionInt } from "../../react/hooks"; +import { LOCALE_IDS } from "@triliumnext/commons"; interface CalendarViewData { @@ -16,8 +17,24 @@ const CALENDAR_VIEWS = [ "listMonth" ] +// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages. +const LOCALE_MAPPINGS: Record Promise<{ default: LocaleInput }>) | null> = { + de: () => import("@fullcalendar/core/locales/de"), + es: () => import("@fullcalendar/core/locales/es"), + fr: () => import("@fullcalendar/core/locales/fr"), + cn: () => import("@fullcalendar/core/locales/zh-cn"), + tw: () => import("@fullcalendar/core/locales/zh-tw"), + ro: () => import("@fullcalendar/core/locales/ro"), + ru: () => import("@fullcalendar/core/locales/ru"), + ja: () => import("@fullcalendar/core/locales/ja"), + "pt_br": () => import("@fullcalendar/core/locales/pt-br"), + uk: () => import("@fullcalendar/core/locales/uk"), + en: null +}; + export default function CalendarView({ note, noteIds }: ViewModeProps) { const plugins = usePlugins(false, false); + const locale = useLocale(); const [ firstDayOfWeek ] = useTriliumOptionInt("firstDayOfWeek"); const [ hideWeekends ] = useNoteLabelBoolean(note, "calendar:hideWeekends"); const [ weekNumbers ] = useNoteLabelBoolean(note, "calendar:weekNumbers"); @@ -35,6 +52,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps ); @@ -61,3 +79,19 @@ function usePlugins(isEditable: boolean, isCalendarRoot: boolean) { return plugins; } + +function useLocale() { + const [ locale ] = useTriliumOption("locale"); + const [ calendarLocale, setCalendarLocale ] = useState(); + + useEffect(() => { + const correspondingLocale = LOCALE_MAPPINGS[locale]; + if (correspondingLocale) { + correspondingLocale().then((locale) => setCalendarLocale(locale.default)); + } else { + setCalendarLocale(undefined); + } + }); + + return calendarLocale; +} diff --git a/apps/client/src/widgets/view_widgets/calendar_view.ts b/apps/client/src/widgets/view_widgets/calendar_view.ts index b738bc2c1..14e849532 100644 --- a/apps/client/src/widgets/view_widgets/calendar_view.ts +++ b/apps/client/src/widgets/view_widgets/calendar_view.ts @@ -17,21 +17,6 @@ import type { TouchBarItem } from "../../components/touch_bar.js"; import type { SegmentedControlSegment } from "electron"; import { LOCALE_IDS } from "@triliumnext/commons"; -// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages. -const LOCALE_MAPPINGS: Record Promise<{ default: LocaleInput }>) | null> = { - de: () => import("@fullcalendar/core/locales/de"), - es: () => import("@fullcalendar/core/locales/es"), - fr: () => import("@fullcalendar/core/locales/fr"), - cn: () => import("@fullcalendar/core/locales/zh-cn"), - tw: () => import("@fullcalendar/core/locales/zh-tw"), - ro: () => import("@fullcalendar/core/locales/ro"), - ru: () => import("@fullcalendar/core/locales/ru"), - ja: () => import("@fullcalendar/core/locales/ja"), - "pt_br": () => import("@fullcalendar/core/locales/pt-br"), - uk: () => import("@fullcalendar/core/locales/uk"), - en: null -}; - // TODO: Deduplicate interface CreateChildResponse { note: { @@ -91,7 +76,6 @@ export default class CalendarView extends ViewMode<{}> { selectable: isEditable, select: (e) => this.#onCalendarSelection(e), eventChange: (e) => this.#onEventMoved(e), - locale: await getFullCalendarLocale(options.get("locale")), height: "100%", nowIndicator: true, handleWindowResize: false, @@ -575,12 +559,3 @@ export default class CalendarView extends ViewMode<{}> { } } - -export async function getFullCalendarLocale(locale: LOCALE_IDS) { - const correspondingLocale = LOCALE_MAPPINGS[locale]; - if (correspondingLocale) { - return (await correspondingLocale()).default; - } else { - return undefined; - } -}