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(react/launch_bar): port ai chat button
Elian Doran991f07e14853
diff --git a/apps/client/src/widgets/buttons/ai_chat_button.ts b/apps/client/src/widgets/buttons/ai_chat_button.tsdeleted file mode 100644index 5ad3f80333..0000000000--- a/apps/client/src/widgets/buttons/ai_chat_button.ts+++ /dev/null@@ -1,26 +0,0 @@-import type { EventData } from "../../components/app_context.js";-import type FNote from "../../entities/fnote.js";-import options from "../../services/options.js";-import CommandButtonWidget from "./command_button.js";--export default class AiChatButton extends CommandButtonWidget {-- constructor(note: FNote) {- super();-- this.command("createAiChat")- .title(() => note.title)- .icon(() => note.getIcon())- .class("launcher-button");- }-- isEnabled() {- return options.get("aiEnabled") === "true";- }-- entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {- if (loadResults.isOptionReloaded("aiEnabled")) {- this.refresh();- }- }-}diff --git a/apps/client/src/widgets/containers/launcher.tsx b/apps/client/src/widgets/containers/launcher.tsxindex fbc40fe2c9..19a46fbf0c 100644--- a/apps/client/src/widgets/containers/launcher.tsx+++ b/apps/client/src/widgets/containers/launcher.tsx@@ -10,10 +10,10 @@ import TodayLauncher from "../buttons/launcher/today_launcher.js";import QuickSearchLauncherWidget from "../quick_search_launcher.js";import type FNote from "../../entities/fnote.js";import type { CommandNames } from "../../components/app_context.js";-import AiChatButton from "../buttons/ai_chat_button.js";import BookmarkButtons from "../launch_bar/BookmarkButtons.jsx";import SpacerWidget from "../launch_bar/SpacerWidget.jsx";import HistoryNavigationButton from "../launch_bar/HistoryNavigation.jsx";+import AiChatButton from "../launch_bar/AiChatButton.jsx";interface InnerWidget extends BasicWidget {settings?: {@@ -125,7 +125,7 @@ export default class LauncherWidget extends BasicWidget {case "quickSearch":return new QuickSearchLauncherWidget(this.isHorizontalLayout);case "aiChatLauncher":- return new AiChatButton(note);+ return <AiChatButton launcherNote={note} />default:throw new Error(`Unrecognized builtin widget ${builtinWidget} for launcher ${note.noteId} "${note.title}"`);}diff --git a/apps/client/src/widgets/launch_bar/AiChatButton.tsx b/apps/client/src/widgets/launch_bar/AiChatButton.tsxnew file mode 100644index 0000000000..2ca95069a9--- /dev/null+++ b/apps/client/src/widgets/launch_bar/AiChatButton.tsx@@ -0,0 +1,18 @@+import FNote from "../../entities/fnote";+import { escapeHtml } from "../../services/utils";+import { useNoteLabel, useNoteProperty, useTriliumOptionBool } from "../react/hooks";+import { LaunchBarActionButton } 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");++ return aiEnabled && iconClass && title && (+ <LaunchBarActionButton+ icon={iconClass}+ text={escapeHtml(title)}+ triggerCommand="createAiChat"+ />+ )+}