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(share): give a shared calendar its navigation back
Elian Doranff0765cdd5c8
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex 3dca1fba7e..80119d090f 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -27,7 +27,7 @@ import Button, { ButtonGroup } from "../../react/Button";import CollapseOnOverflow from "../../react/CollapseOnOverflow";import Dropdown from "../../react/Dropdown";import { FormListItem } from "../../react/FormList";-import { useNoteLabel, useNoteLabelBoolean, useSpacedUpdate, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";+import { useEffectiveReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useSpacedUpdate, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";import { ParentComponent } from "../../react/react_utils";import { ViewModeProps } from "../interface";import { changeEvent, newEvent } from "./api";@@ -123,6 +123,8 @@ export const LOCALE_MAPPINGS: Record<DISPLAYABLE_LOCALE_IDS, (() => Promise<{ deexport default function CalendarView({ note, noteIds }: ViewModeProps<CalendarViewData>) {const parentComponent = useContext(ParentComponent);+ const { noteContext } = useNoteContext();+ const isReadOnly = useEffectiveReadOnly(note, noteContext);const containerRef = useRef<HTMLDivElement>(null);const calendarRef = useRef<FullCalendar>(null);// The event the view's popovers stand for — a chip clicked, or a range just dragged out (see@@ -143,7 +145,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi// FullCalendar v7 sizes itself from its own ResizeObserver; the v6 `updateSize()` nudge this// used to need is gone along with the method.const isCalendarRoot = (calendarRoot || workspaceCalendarRoot);- const isEditable = !isCalendarRoot;+ const isEditable = !isCalendarRoot && !isReadOnly;// Worked out once and handed to both the grid and the tap that makes an event of one of its// slots (see draftFromDateClick), so that the two cannot come to disagree on a slot's length.const effectiveSlotDuration = isValidDuration(slotDuration) ? slotDuration : DEFAULT_SLOT_DURATION;@@ -329,7 +331,9 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVireturn (plugins &&<div className="calendar-view" ref={containerRef} tabIndex={100}>- <CalendarCollectionProperties note={note} calendarRef={calendarRef} containerRef={containerRef} />+ <CalendarCollectionProperties+ note={note} calendarRef={calendarRef} containerRef={containerRef} isReadOnly={isReadOnly}+ /><Calendarevents={eventBuilder}calendarRef={calendarRef}@@ -376,7 +380,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVieventInnerClass={eventInnerClass}eventDidMount={eventDidMount}viewDidMount={({ view }) => {- if (initialView.current !== view.type) {+ // A read-only calendar keeps the view it was switched to only while it is shown.+ if (initialView.current !== view.type && !isReadOnly) {initialView.current = view.type;viewSpacedUpdate.scheduleUpdate();}@@ -409,10 +414,11 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi);}-function CalendarCollectionProperties({ note, calendarRef, containerRef }: {+function CalendarCollectionProperties({ note, calendarRef, containerRef, isReadOnly }: {note: FNote;calendarRef: RefObject<FullCalendar | null>;containerRef: RefObject<HTMLDivElement | null>;+ isReadOnly: boolean;}) {const { title, viewType: currentViewType } = useOnDatesSet(calendarRef);const currentViewData = CALENDAR_VIEWS.find(v => calendarRef.current && v.type === currentViewType);@@ -426,7 +432,7 @@ function CalendarCollectionProperties({ note, calendarRef, containerRef }: {<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} />+ {!isReadOnly && <PinDateButton note={note} calendarRef={calendarRef} />}{/* On a phone the switcher is a menu whatever the width, and stands with the daterather than on a right-hand end the wrapped bar no longer has. */}{isMobileLocal && <CalendarViewSwitcher calendarRef={calendarRef} containerRef={containerRef} />}diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsxindex 39113cad8f..044221375e 100644--- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx+++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx@@ -53,12 +53,12 @@ interface CollectionPropertiesProps {optionsChildren?: ComponentChildren;}-/** The bar above a collection that switches its view and sets its options; a shared page has none. */-export default function CollectionProperties(props: CollectionPropertiesProps) {- return isShare ? null : <CollectionPropertiesBar {...props} />;-}--function CollectionPropertiesBar({+/**+ * The bar above a collection that switches its view, sets its options and holds the view's own+ * controls, such as a calendar's navigation. A shared page keeps only the view's own controls, as a+ * visitor cannot change the note.+ */+export default function CollectionProperties({note,centerChildren,rightChildren,@@ -71,15 +71,17 @@ function CollectionPropertiesBar({return ([ "book", "search" ].includes(noteType ?? "") &&<div className="collection-properties"><div className="left-container">- <ViewTypeSwitcher viewType={viewType} setViewType={setViewType} />- <ViewOptions note={note} viewType={viewType} optionsChildren={optionsChildren} />+ {!isShare && <>+ <ViewTypeSwitcher viewType={viewType} setViewType={setViewType} />+ <ViewOptions note={note} viewType={viewType} optionsChildren={optionsChildren} />+ </>}</div><div className="center-container">{centerChildren}</div><div className="right-container">{rightChildren}- {noteType === "search" && (+ {noteType === "search" && !isShare && (<OpenAllButton note={note} isOpening={isOpening} setIsOpening={setIsOpening} />)}</div>diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.htmlindex d0124cc9ac..9569ab2bf0 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html@@ -57,6 +57,10 @@<li>The length of an event can be changed by placing the mouse to the rightedge of the event and dragging the mouse around.</li></ul>+<p>On a <a href="#root/_help_CoFPLs3dRlXc">read-only</a> calendar, events can't+ be dragged, resized or created, and the button to pin the current date+ is hidden. Switching between the month, week and day views still works,+ but the choice isn't saved.</p><h3>Popup view</h3><p>When an event is clicked, a popup will show near the event which containsthe following inforamtion:</p>diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.mdindex 7d7cc0c16c..1218c785ae 100644--- a/docs/User Guide/User Guide/Collections/Calendar.md+++ b/docs/User Guide/User Guide/Collections/Calendar.md@@ -42,6 +42,8 @@ After creating the event, it will show up on the calendar. To edit the content o* Drag and drop an event on the calendar to move it to another day.* The length of an event can be changed by placing the mouse to the right edge of the event and dragging the mouse around.+On a [read-only](../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md) calendar, events can't be dragged, resized or created, and the button to pin the current date is hidden. Switching between the month, week and day views still works, but the choice isn't saved.+### Popup viewWhen an event is clicked, a popup will show near the event which contains the following inforamtion: