refactor(launch_bar): deduplicate launcher note props

This commit is contained in:
Elian Doran 2025-12-05 17:16:55 +02:00
parent a107c126e4
commit a53322e7cb
No known key found for this signature in database
3 changed files with 13 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import { Dispatch, StateUpdater, useEffect, useMemo, useRef, useState } from "preact/hooks"; import { Dispatch, StateUpdater, useEffect, useMemo, useRef, useState } from "preact/hooks";
import FNote from "../../entities/fnote"; import FNote from "../../entities/fnote";
import { LaunchBarDropdownButton, useLauncherIconAndTitle } from "./launch_bar_widgets"; import { LaunchBarDropdownButton, LauncherNoteProps, useLauncherIconAndTitle } from "./launch_bar_widgets";
import { Dayjs, dayjs } from "@triliumnext/commons"; import { Dayjs, dayjs } from "@triliumnext/commons";
import appContext from "../../components/app_context"; import appContext from "../../components/app_context";
import "./CalendarWidget.css"; import "./CalendarWidget.css";
@ -30,7 +30,7 @@ const MONTHS = [
t("calendar.december") t("calendar.december")
]; ];
export default function CalendarWidget({ launcherNote }: { launcherNote: FNote }) { export default function CalendarWidget({ launcherNote }: LauncherNoteProps) {
const { title, icon } = useLauncherIconAndTitle(launcherNote); const { title, icon } = useLauncherIconAndTitle(launcherNote);
const [ calendarArgs, setCalendarArgs ] = useState<Pick<CalendarArgs, "activeDate" | "todaysDate">>(); const [ calendarArgs, setCalendarArgs ] = useState<Pick<CalendarArgs, "activeDate" | "todaysDate">>();
const [ date, setDate ] = useState<Dayjs>(); const [ date, setDate ] = useState<Dayjs>();

View File

@ -7,12 +7,12 @@ import QuickSearchWidget from "../quick_search";
import { isMobile } from "../../services/utils"; import { isMobile } from "../../services/utils";
import date_notes from "../../services/date_notes"; import date_notes from "../../services/date_notes";
import { CustomNoteLauncher } from "./GenericButtons"; import { CustomNoteLauncher } from "./GenericButtons";
import { LaunchBarActionButton, LaunchBarContext, useLauncherIconAndTitle } from "./launch_bar_widgets"; import { LaunchBarActionButton, LaunchBarContext, LauncherNoteProps, useLauncherIconAndTitle } from "./launch_bar_widgets";
import dialog from "../../services/dialog"; import dialog from "../../services/dialog";
import { t } from "../../services/i18n"; import { t } from "../../services/i18n";
import { CommandNames } from "../../components/app_context"; import { CommandNames } from "../../components/app_context";
export function CommandButton({ launcherNote }: { launcherNote: FNote }) { export function CommandButton({ launcherNote }: LauncherNoteProps) {
const { icon, title } = useLauncherIconAndTitle(launcherNote); const { icon, title } = useLauncherIconAndTitle(launcherNote);
const [ command ] = useNoteLabel(launcherNote, "command"); const [ command ] = useNoteLabel(launcherNote, "command");
@ -50,7 +50,7 @@ export function NoteLauncher({ launcherNote, ...restProps }: { launcherNote: FNo
); );
} }
export function ScriptLauncher({ launcherNote }: { launcherNote: FNote }) { export function ScriptLauncher({ launcherNote }: LauncherNoteProps) {
const { icon, title } = useLauncherIconAndTitle(launcherNote); const { icon, title } = useLauncherIconAndTitle(launcherNote);
return ( return (
<LaunchBarActionButton <LaunchBarActionButton
@ -70,7 +70,7 @@ export function ScriptLauncher({ launcherNote }: { launcherNote: FNote }) {
) )
} }
export default function AiChatButton({ launcherNote }: { launcherNote: FNote }) { export default function AiChatButton({ launcherNote }: LauncherNoteProps) {
const [ aiEnabled ] = useTriliumOptionBool("aiEnabled"); const [ aiEnabled ] = useTriliumOptionBool("aiEnabled");
const { icon, title } = useLauncherIconAndTitle(launcherNote); const { icon, title } = useLauncherIconAndTitle(launcherNote);
@ -83,7 +83,7 @@ export default function AiChatButton({ launcherNote }: { launcherNote: FNote })
) )
} }
export function TodayLauncher({ launcherNote }: { launcherNote: FNote }) { export function TodayLauncher({ launcherNote }: LauncherNoteProps) {
return ( return (
<CustomNoteLauncher <CustomNoteLauncher
launcherNote={launcherNote} launcherNote={launcherNote}
@ -109,7 +109,7 @@ export function QuickSearchLauncherWidget() {
) )
} }
export function CustomWidget({ launcherNote }: { launcherNote: FNote }) { export function CustomWidget({ launcherNote }: LauncherNoteProps) {
const [ widgetNote ] = useNoteRelationTarget(launcherNote, "widget"); const [ widgetNote ] = useNoteRelationTarget(launcherNote, "widget");
const [ widget, setWidget ] = useState<BasicWidget>(); const [ widget, setWidget ] = useState<BasicWidget>();
const parentComponent = useContext(ParentComponent) as BasicWidget | null; const parentComponent = useContext(ParentComponent) as BasicWidget | null;

View File

@ -13,6 +13,11 @@ export const LaunchBarContext = createContext<{
isHorizontalLayout: false isHorizontalLayout: false
}) })
export interface LauncherNoteProps {
/** The corresponding {@link FNote} of type {@code launcher} in the hidden subtree of this launcher. Generally this launcher note holds information about the launcher via labels and relations, but also the title and the icon of the launcher. Not to be confused with the target note, which is specific to some launchers. */
launcherNote: FNote;
}
export function LaunchBarActionButton(props: Omit<ActionButtonProps, "className" | "noIconActionClass" | "titlePosition">) { export function LaunchBarActionButton(props: Omit<ActionButtonProps, "className" | "noIconActionClass" | "titlePosition">) {
const { isHorizontalLayout } = useContext(LaunchBarContext); const { isHorizontalLayout } = useContext(LaunchBarContext);