diff --git a/apps/client/src/widgets/collections/calendar/calendar.tsx b/apps/client/src/widgets/collections/calendar/calendar.tsx index 18be5950a..bd1b5d126 100644 --- a/apps/client/src/widgets/collections/calendar/calendar.tsx +++ b/apps/client/src/widgets/collections/calendar/calendar.tsx @@ -4,10 +4,9 @@ import { RefObject } from "preact"; interface CalendarProps extends CalendarOptions { calendarRef?: RefObject; - tabIndex?: number; } -export default function Calendar({ tabIndex, calendarRef, ...options }: CalendarProps) { +export default function Calendar({ calendarRef, ...options }: CalendarProps) { const containerRef = useRef(null); useLayoutEffect(() => { @@ -24,6 +23,6 @@ export default function Calendar({ tabIndex, calendarRef, ...options }: Calendar }, [ containerRef, options ]); return ( -
+
); } diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx index fc5a0c1da..4be81910d 100644 --- a/apps/client/src/widgets/collections/calendar/index.tsx +++ b/apps/client/src/widgets/collections/calendar/index.tsx @@ -19,6 +19,7 @@ import FNote from "../../../entities/fnote"; import Button, { ButtonGroup } from "../../react/Button"; import ActionButton from "../../react/ActionButton"; import { RefObject } from "preact"; +import TouchBar, { TouchBarLabel, TouchBarSegmentedControl } from "../../react/TouchBar"; interface CalendarViewData { @@ -114,13 +115,12 @@ export default function CalendarView({ note, noteIds }: ViewModeProps +
+
); } @@ -305,8 +306,36 @@ function useEventDisplayCustomization() { return { eventDidMount }; } -function useTouchBarCustomization(api: FullCalendar) { - useTouchBar(() => { +function CalendarTouchBar({ calendarRef }: { calendarRef: RefObject }) { + // Wait for the calendar ref to become available. + const [ ready, setReady ] = useState(false); + useEffect(() => setReady(true), []); + const [ , setTitle ] = useState(); + const viewType = calendarRef.current?.view.type; - }, [ api ]); + useEffect(() => { + const api = calendarRef.current; + + function onDatesSet() { + setTitle(calendarRef.current?.view.title); + } + + onDatesSet(); + api?.on("datesSet", onDatesSet); + return () => api?.off("datesSet", onDatesSet) + }, [ calendarRef ]); + + return ready && ( + + + ({ + label: name, + }))} + selectedIndex={CALENDAR_VIEWS.findIndex(v => v.type === viewType) ?? 0} + onChange={(selectedIndex) => calendarRef.current?.changeView(CALENDAR_VIEWS[selectedIndex].type)} + /> + + ); } diff --git a/apps/client/src/widgets/react/TouchBar.tsx b/apps/client/src/widgets/react/TouchBar.tsx index ba2e664b0..026995fa9 100644 --- a/apps/client/src/widgets/react/TouchBar.tsx +++ b/apps/client/src/widgets/react/TouchBar.tsx @@ -26,6 +26,15 @@ interface ButtonProps { enabled?: boolean; } +interface SegmentedControlProps { + mode: "single" | "buttons"; + segments: { + label: string; + }[]; + selectedIndex?: number; + onChange?: (selectedIndex: number, isSelected: boolean) => void; +} + interface TouchBarContextApi { addItem(item: TouchBarItem): void; TouchBar: typeof Electron.TouchBar; @@ -72,6 +81,8 @@ export default function TouchBar({ children }: TouchBarProps) { } }); + console.log("Touch bar state", isFocused, items); + return ( {children} @@ -119,3 +130,17 @@ export function TouchBarButton({ label, click, enabled }: ButtonProps) { return <>; } + +export function TouchBarSegmentedControl({ mode, segments, selectedIndex, onChange }: SegmentedControlProps) { + const api = useContext(TouchBarContext); + + if (api) { + const item = new api.TouchBar.TouchBarSegmentedControl({ + mode, segments, selectedIndex, + change: onChange + }); + api.addItem(item); + } + + return <>; +} diff --git a/apps/client/src/widgets/view_widgets/calendar_view.ts b/apps/client/src/widgets/view_widgets/calendar_view.ts index c931d91c7..e689e1bc4 100644 --- a/apps/client/src/widgets/view_widgets/calendar_view.ts +++ b/apps/client/src/widgets/view_widgets/calendar_view.ts @@ -61,11 +61,6 @@ export default class CalendarView extends ViewMode<{}> { } index++; - // Text button. - if (subItem.innerText) { - segments.push({ label: subItem.innerText }); - continue; - } // Icon button. const iconEl = subItem.querySelector("span.fc-icon");