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
refactor(widgets): relocate note launcher & command button
Elian Doran83e599f0e9d9
diff --git a/apps/client/src/widgets/launch_bar/GenericButtons.tsx b/apps/client/src/widgets/launch_bar/GenericButtons.tsxindex e9759343ec..06e5bd7508 100644--- a/apps/client/src/widgets/launch_bar/GenericButtons.tsx+++ b/apps/client/src/widgets/launch_bar/GenericButtons.tsx@@ -1,24 +1,8 @@-import appContext, { CommandNames } from "../../components/app_context";+import appContext from "../../components/app_context";import FNote from "../../entities/fnote";import link_context_menu from "../../menus/link_context_menu";import { escapeHtml, isCtrlKey } from "../../services/utils";-import { useNoteLabel } from "../react/hooks";import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets";-import dialog from "../../services/dialog";-import { t } from "../../services/i18n";--export function CommandButton({ launcherNote }: { launcherNote: FNote }) {- const { icon, title } = useLauncherIconAndTitle(launcherNote);- const [ command ] = useNoteLabel(launcherNote, "command");-- return command && (- <LaunchBarActionButton- icon={icon}- text={title}- triggerCommand={command as CommandNames}- />- )-}export function CustomNoteLauncher({ launcherNote, getTargetNoteId, getHoistedNoteId }: {launcherNote: FNote,@@ -62,28 +46,3 @@ export function CustomNoteLauncher({ launcherNote, getTargetNoteId, getHoistedNo/>)}--// we're intentionally displaying the launcher title and icon instead of the target,-// e.g. you want to make launchers to 2 mermaid diagrams which both have mermaid icon (ok),-// but on the launchpad you want them distinguishable.-// for titles, the note titles may follow a different scheme than maybe desirable on the launchpad-// another reason is the discrepancy between what user sees on the launchpad and in the config (esp. icons).-// The only downside is more work in setting up the typical case-// where you actually want to have both title and icon in sync, but for those cases there are bookmarks-export function NoteLauncher({ launcherNote, ...restProps }: { launcherNote: FNote, hoistedNoteId?: string }) {- return (- <CustomNoteLauncher- launcherNote={launcherNote}- getTargetNoteId={(launcherNote) => {- const targetNoteId = launcherNote.getRelationValue("target");- if (!targetNoteId) {- dialog.info(t("note_launcher.this_launcher_doesnt_define_target_note"));- return null;- }- return targetNoteId;- }}- getHoistedNoteId={launcherNote => launcherNote.getRelationValue("hoistedNote")}- {...restProps}- />- );-}diff --git a/apps/client/src/widgets/launch_bar/LauncherContainer.tsx b/apps/client/src/widgets/launch_bar/LauncherContainer.tsxindex a6a5d8a68d..5d48bc6452 100644--- a/apps/client/src/widgets/launch_bar/LauncherContainer.tsx+++ b/apps/client/src/widgets/launch_bar/LauncherContainer.tsx@@ -8,9 +8,8 @@ import BookmarkButtons from "./BookmarkButtons";import ProtectedSessionStatusWidget from "./ProtectedSessionStatusWidget";import SyncStatus from "./SyncStatus";import HistoryNavigationButton from "./HistoryNavigation";-import { CustomWidget, QuickSearchLauncherWidget, ScriptLauncher, TodayLauncher } from "./LauncherDefinitions";+import { CommandButton, CustomWidget, NoteLauncher, QuickSearchLauncherWidget, ScriptLauncher, TodayLauncher } from "./LauncherDefinitions";import AiChatButton from "./AiChatButton";-import { CommandButton, NoteLauncher } from "./GenericButtons";import { useTriliumEvent } from "../react/hooks";export default function LauncherContainer({ isHorizontalLayout }: { isHorizontalLayout: boolean }) {diff --git a/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx b/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsxindex f21baa819f..91f8a794f1 100644--- a/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx+++ b/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx@@ -1,5 +1,5 @@import { useContext, useEffect, useMemo, useState } from "preact/hooks";-import { useLegacyWidget, useNoteContext, useNoteRelationTarget } from "../react/hooks";+import { useLegacyWidget, useNoteContext, useNoteLabel, useNoteRelationTarget } from "../react/hooks";import { ParentComponent } from "../react/react_utils";import BasicWidget from "../basic_widget";import FNote from "../../entities/fnote";@@ -8,6 +8,47 @@ import { isMobile } from "../../services/utils";import date_notes from "../../services/date_notes";import { CustomNoteLauncher } from "./GenericButtons";import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets";+import dialog from "../../services/dialog";+import { t } from "../../services/i18n";+import { CommandNames } from "../../components/app_context";++export function CommandButton({ launcherNote }: { launcherNote: FNote }) {+ const { icon, title } = useLauncherIconAndTitle(launcherNote);+ const [ command ] = useNoteLabel(launcherNote, "command");++ return command && (+ <LaunchBarActionButton+ icon={icon}+ text={title}+ triggerCommand={command as CommandNames}+ />+ )+}++// we're intentionally displaying the launcher title and icon instead of the target,+// e.g. you want to make launchers to 2 mermaid diagrams which both have mermaid icon (ok),+// but on the launchpad you want them distinguishable.+// for titles, the note titles may follow a different scheme than maybe desirable on the launchpad+// another reason is the discrepancy between what user sees on the launchpad and in the config (esp. icons).+// The only downside is more work in setting up the typical case+// where you actually want to have both title and icon in sync, but for those cases there are bookmarks+export function NoteLauncher({ launcherNote, ...restProps }: { launcherNote: FNote, hoistedNoteId?: string }) {+ return (+ <CustomNoteLauncher+ launcherNote={launcherNote}+ getTargetNoteId={(launcherNote) => {+ const targetNoteId = launcherNote.getRelationValue("target");+ if (!targetNoteId) {+ dialog.info(t("note_launcher.this_launcher_doesnt_define_target_note"));+ return null;+ }+ return targetNoteId;+ }}+ getHoistedNoteId={launcherNote => launcherNote.getRelationValue("hoistedNote")}+ {...restProps}+ />+ );+}export function ScriptLauncher({ launcherNote }: { launcherNote: FNote }) {const { icon, title } = useLauncherIconAndTitle(launcherNote);