import { Dispatch, StateUpdater, useEffect, useState } from "preact/hooks"; import FNote from "../../entities/fnote"; import { LaunchBarDropdownButton, useLauncherIconAndTitle } from "./launch_bar_widgets"; import { Dayjs, dayjs } from "@triliumnext/commons"; import appContext from "../../components/app_context"; import "./CalendarWidget.css"; import Calendar from "./Calendar"; import ActionButton from "../react/ActionButton"; export default function CalendarWidget({ launcherNote }: { launcherNote: FNote }) { const { title, icon } = useLauncherIconAndTitle(launcherNote); const [ date, setDate ] = useState(); return ( { const dateNote = appContext.tabManager.getActiveContextNote()?.getOwnedLabelValue("dateNote"); const activeDate = dateNote ? dayjs(`${dateNote}T12:00:00`) : null; const todaysDate = dayjs(); const date = dayjs(activeDate || todaysDate).startOf('month'); setDate(date); }} > {date &&
}
) } interface CalendarHeaderProps { date: Dayjs; setDate: Dispatch>; } function CalendarHeader(props: CalendarHeaderProps) { return (
) } function CalendarMonthSelector({ date, setDate }: CalendarHeaderProps) { return (
); } function AdjustDateButton({ date, setDate, unit, direction }: CalendarHeaderProps & { direction: "prev" | "next", unit: "month" }) { return ( { e.stopPropagation(); const newDate = direction === "prev" ? date.subtract(1, unit) : date.add(1, unit); setDate(newDate); }} /> ) }