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
feat(collections/calendar): use own UI for header
Elian Doranafc17f41f602
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 2aefbbc015..a3e08ff591 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -293,6 +293,11 @@ button.close:hover {pointer-events: none;}+.icon-action.btn {+ padding: 0 8px;+ min-width: unset !important;+}+.ui-widget-content a:not(.ui-tabs-anchor) {color: #337ab7 !important;}diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 81c0cacc74..d10669b46a 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -587,7 +587,17 @@"september": "September","october": "October","november": "November",- "december": "December"+ "december": "December",+ "week": "Week",+ "week_previous": "Previous week",+ "week_next": "Next week",+ "month": "Month",+ "month_previous": "Previous month",+ "month_next": "Next month",+ "year": "Year",+ "year_previous": "Previous year",+ "year_next": "Next year",+ "list": "List"},"close_pane_button": {"close_this_pane": "Close this pane"diff --git a/apps/client/src/widgets/collections/calendar/index.css b/apps/client/src/widgets/collections/calendar/index.cssindex 69b116a182..2f4103106b 100644--- a/apps/client/src/widgets/collections/calendar/index.css+++ b/apps/client/src/widgets/collections/calendar/index.css@@ -59,4 +59,21 @@ body.desktop:not(.zen) .calendar-container .fc-toolbar.fc-header-toolbar {font-size: 0.85em;opacity: 0.85;overflow: hidden;-}\ No newline at end of file+}++/* #region Header */+.calendar-header {+ margin-bottom: 10px;+ display: flex;+ align-items: center;+ gap: 10px;+}++.calendar-header .btn {+ min-width: unset !important;+}++.calendar-header > .title {+ flex-grow: 1;+}+/* #endregion */\ No newline at end of filediff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex 19ff79040c..a135fa9047 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -16,18 +16,50 @@ import date_notes from "../../../services/date_notes";import appContext from "../../../components/app_context";import { DateClickArg } from "@fullcalendar/interaction";import FNote from "../../../entities/fnote";+import Button, { ButtonGroup } from "../../react/Button";+import ActionButton from "../../react/ActionButton";+import { RefObject } from "preact";interface CalendarViewData {}+interface CalendarViewData {+ type: string;+ name: string;+ previousText: string;+ nextText: string;+}+const CALENDAR_VIEWS = [- "timeGridWeek",- "dayGridMonth",- "multiMonthYear",- "listMonth"+ {+ type: "timeGridWeek",+ name: t("calendar.week"),+ previousText: t("calendar.week_previous"),+ nextText: t("calendar.week_next")+ },+ {+ type: "dayGridMonth",+ name: t("calendar.month"),+ previousText: t("calendar.month_previous"),+ nextText: t("calendar.month_next")+ },+ {+ type: "multiMonthYear",+ name: t("calendar.year"),+ previousText: t("calendar.year_previous"),+ nextText: t("calendar.year_next")+ },+ {+ type: "listMonth",+ name: t("calendar.list"),+ previousText: t("calendar.month_previous"),+ nextText: t("calendar.month_next")+ }]+const SUPPORTED_CALENDAR_VIEW_TYPE = CALENDAR_VIEWS.map(v => v.type);+// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages.export const LOCALE_MAPPINGS: Record<LOCALE_IDS, (() => Promise<{ default: LocaleInput }>) | null> = {de: () => import("@fullcalendar/core/locales/de"),@@ -83,20 +115,18 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVireturn (plugins &&<div className="calendar-view" ref={containerRef}>+ <CalendarHeader calendarRef={calendarRef} /><Calendarevents={eventBuilder}calendarRef={calendarRef}plugins={plugins}tabIndex={100}- initialView={initialView.current && CALENDAR_VIEWS.includes(initialView.current) ? initialView.current : "dayGridMonth"}- headerToolbar={{- start: "title",- end: `${CALENDAR_VIEWS.join(",")} today prev,next`- }}+ initialView={initialView.current && SUPPORTED_CALENDAR_VIEW_TYPE.includes(initialView.current) ? initialView.current : "dayGridMonth"}+ headerToolbar={false}firstDay={firstDayOfWeek ?? 0}weekends={!hideWeekends}weekNumbers={weekNumbers}- height="100%"+ height="90%"nowIndicatorhandleWindowResize={false}locale={locale}@@ -113,6 +143,31 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi);}+function CalendarHeader({ calendarRef }: { calendarRef: RefObject<FullCalendar> }) {+ const currentViewType = calendarRef.current?.view?.type;+ const currentViewData = CALENDAR_VIEWS.find(v => calendarRef.current && v.type === currentViewType);++ return (+ <div className="calendar-header">+ <span className="title">{calendarRef.current?.view.title}</span>+ <ButtonGroup>+ {CALENDAR_VIEWS.map(viewData => (+ <Button+ text={viewData.name.toLocaleLowerCase()}+ className={currentViewType === viewData.type ? "active" : ""}+ onClick={() => calendarRef.current?.changeView(viewData.type)}+ />+ ))}+ </ButtonGroup>+ <Button text="today" onClick={() => calendarRef.current?.today()} />+ <ButtonGroup>+ <ActionButton icon="bx bx-chevron-left" text={currentViewData?.previousText ?? ""} frame onClick={() => calendarRef.current?.prev()} />+ <ActionButton icon="bx bx-chevron-right" text={currentViewData?.nextText ?? ""} frame onClick={() => calendarRef.current?.next()} />+ </ButtonGroup>+ </div>+ )+}+function usePlugins(isEditable: boolean, isCalendarRoot: boolean) {const [ plugins, setPlugins ] = useState<PluginDef[]>();diff --git a/apps/client/src/widgets/react/ActionButton.tsx b/apps/client/src/widgets/react/ActionButton.tsxindex 5e6f3266b5..2eb69bab81 100644--- a/apps/client/src/widgets/react/ActionButton.tsx+++ b/apps/client/src/widgets/react/ActionButton.tsx@@ -11,18 +11,19 @@ export interface ActionButtonProps {onClick?: (e: MouseEvent) => void;triggerCommand?: CommandNames;noIconActionClass?: boolean;+ frame?: boolean;}-export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass }: ActionButtonProps) {+export default function ActionButton({ text, icon, className, onClick, triggerCommand, titlePosition, noIconActionClass, frame }: ActionButtonProps) {const buttonRef = useRef<HTMLButtonElement>(null);const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();-+useStaticTooltip(buttonRef, {title: keyboardShortcut?.length ? `${text} (${keyboardShortcut?.join(",")})` : text,placement: titlePosition ?? "bottom",fallbackPlacements: [ titlePosition ?? "bottom" ]});-+useEffect(() => {if (triggerCommand) {keyboard_actions.getAction(triggerCommand, true).then(action => setKeyboardShortcut(action?.effectiveShortcuts));@@ -31,8 +32,8 @@ export default function ActionButton({ text, icon, className, onClick, triggerCoreturn <buttonref={buttonRef}- class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon}`}- onClick={onClick}+ class={`${className ?? ""} ${!noIconActionClass ? "icon-action" : "btn"} ${icon} ${frame ? "btn btn-primary" : ""}`}+ onClick={onClick}data-trigger-command={triggerCommand}/>;-}\ No newline at end of file+}diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsxindex 585e8b1dd5..d20c5e19d1 100644--- a/apps/client/src/widgets/react/Button.tsx+++ b/apps/client/src/widgets/react/Button.tsx@@ -1,4 +1,4 @@-import type { RefObject } from "preact";+import type { ComponentChildren, RefObject } from "preact";import type { CSSProperties } from "preact/compat";import { useMemo } from "preact/hooks";import { memo } from "preact/compat";@@ -72,4 +72,12 @@ const Button = memo(({ name, buttonRef, className, text, onClick, keyboardShortc);});-export default Button;\ No newline at end of file+export function ButtonGroup({ children }: { children: ComponentChildren }) {+ return (+ <div className="btn-group" role="group">+ {children}+ </div>+ )+}++export default Button;