diff --git a/apps/client/src/widgets/launch_bar/AiChatButton.tsx b/apps/client/src/widgets/launch_bar/AiChatButton.tsx index 2ca95069a..cd0d05e08 100644 --- a/apps/client/src/widgets/launch_bar/AiChatButton.tsx +++ b/apps/client/src/widgets/launch_bar/AiChatButton.tsx @@ -1,17 +1,15 @@ import FNote from "../../entities/fnote"; -import { escapeHtml } from "../../services/utils"; -import { useNoteLabel, useNoteProperty, useTriliumOptionBool } from "../react/hooks"; -import { LaunchBarActionButton } from "./launch_bar_widgets"; +import { useTriliumOptionBool } from "../react/hooks"; +import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets"; export default function AiChatButton({ launcherNote }: { launcherNote: FNote }) { const [ aiEnabled ] = useTriliumOptionBool("aiEnabled"); - const [ iconClass ] = useNoteLabel(launcherNote, "iconClass"); - const title = useNoteProperty(launcherNote, "title"); + const { icon, title } = useLauncherIconAndTitle(launcherNote); - return aiEnabled && iconClass && title && ( + return aiEnabled && ( ) diff --git a/apps/client/src/widgets/launch_bar/BookmarkButtons.tsx b/apps/client/src/widgets/launch_bar/BookmarkButtons.tsx index bf8b6cead..17bf1f614 100644 --- a/apps/client/src/widgets/launch_bar/BookmarkButtons.tsx +++ b/apps/client/src/widgets/launch_bar/BookmarkButtons.tsx @@ -1,9 +1,8 @@ import { useMemo } from "preact/hooks"; -import { LaunchBarDropdownButton, type LaunchBarWidgetProps } from "./launch_bar_widgets"; +import { LaunchBarDropdownButton, useLauncherIconAndTitle, type LaunchBarWidgetProps } from "./launch_bar_widgets"; import { CSSProperties } from "preact"; import type FNote from "../../entities/fnote"; -import { useChildNotes, useNoteLabel, useNoteLabelBoolean, useNoteProperty } from "../react/hooks"; -import { escapeHtml } from "../../services/utils"; +import { useChildNotes, useNoteLabelBoolean } from "../react/hooks"; import "./BookmarkButtons.css"; import NoteLink from "../react/NoteLink"; import { NoteLauncher } from "./GenericButtons"; @@ -33,14 +32,13 @@ function SingleBookmark({ note }: { note: FNote }) { } function BookmarkFolder({ note }: { note: FNote }) { - const [ iconClass ] = useNoteLabel(note, "iconClass"); - const title = useNoteProperty(note, "title"); + const { icon, title } = useLauncherIconAndTitle(note); const childNotes = useChildNotes(note.noteId); - return title && iconClass && ( + return (
diff --git a/apps/client/src/widgets/launch_bar/GenericButtons.tsx b/apps/client/src/widgets/launch_bar/GenericButtons.tsx index 56fe4daa7..4e09a835c 100644 --- a/apps/client/src/widgets/launch_bar/GenericButtons.tsx +++ b/apps/client/src/widgets/launch_bar/GenericButtons.tsx @@ -3,25 +3,23 @@ import FNote from "../../entities/fnote"; import link_context_menu from "../../menus/link_context_menu"; import { escapeHtml, isCtrlKey } from "../../services/utils"; import { useNoteLabel, useNoteProperty } from "../react/hooks"; -import { LaunchBarActionButton } from "./launch_bar_widgets"; +import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets"; export function CommandButton({ launcherNote }: { launcherNote: FNote }) { - const [ iconClass ] = useNoteLabel(launcherNote, "iconClass"); + const { icon, title } = useLauncherIconAndTitle(launcherNote); const [ command ] = useNoteLabel(launcherNote, "command"); - const title = useNoteProperty(launcherNote, "title"); - return iconClass && title && command && ( + return command && ( ) } export function NoteLauncher({ launcherNote, targetNoteId, hoistedNoteId }: { launcherNote: FNote, targetNoteId: string, hoistedNoteId?: string }) { - const [ iconClass ] = useNoteLabel(launcherNote, "iconClass"); - const title = useNoteProperty(launcherNote, "title"); + const { icon, title } = useLauncherIconAndTitle(launcherNote); async function launch(evt: MouseEvent) { if (evt.which === 3) { @@ -38,9 +36,9 @@ export function NoteLauncher({ launcherNote, targetNoteId, hoistedNoteId }: { la } } - return title && iconClass && ( + return ( (null); useEffect(() => { @@ -27,10 +25,10 @@ export default function HistoryNavigationButton({ launcherNote, command }: Histo } }, []); - return iconClass && title && ( + return ( { e.preventDefault(); diff --git a/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx b/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx index 1ea64a852..5a72e0f54 100644 --- a/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx +++ b/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx @@ -1,5 +1,8 @@ +import FNote from "../../entities/fnote"; +import { escapeHtml } from "../../services/utils"; import ActionButton, { ActionButtonProps } from "../react/ActionButton"; import Dropdown, { DropdownProps } from "../react/Dropdown"; +import { useNoteLabel, useNoteProperty } from "../react/hooks"; import Icon from "../react/Icon"; export interface LaunchBarWidgetProps { @@ -28,3 +31,16 @@ export function LaunchBarDropdownButton({ children, icon, ...props }: Pick{children} ) } + +export function useLauncherIconAndTitle(note: FNote) { + const title = useNoteProperty(note, "title"); + + // React to changes. + useNoteLabel(note, "iconClass"); + useNoteLabel(note, "workspaceIconClass"); + + return { + icon: note.getIcon(), + title: escapeHtml(title ?? "") + }; +}