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
fix(llm): toggle sidebar chat widget reactively on AI enable/disable
Elian Doran2b7f9e2ab606
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsxindex 75dfe0566f..a59d80d6e4 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx@@ -7,12 +7,12 @@ import { useCallback, useEffect, useRef, useState } from "preact/hooks";import appContext from "../../components/app_context";import { WidgetsByParent } from "../../services/bundle";-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";import { t } from "../../services/i18n";import options from "../../services/options";import { DEFAULT_GUTTER_SIZE } from "../../services/resizer";+import { isStandalone } from "../../services/utils";import Button from "../react/Button";-import { useActiveNoteContext, useLegacyWidget, useNoteProperty, useTriliumEvent, useTriliumOptionJson } from "../react/hooks";+import { useActiveNoteContext, useLegacyWidget, useNoteProperty, useTriliumEvent, useTriliumOptionBool, useTriliumOptionJson } from "../react/hooks";import LazyComponent from "../react/LazyComponent";import NoItems from "../react/NoItems";import LegacyRightPanelWidget from "../right_panel_widget";@@ -70,6 +70,8 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent) {const noteType = useNoteProperty(note, "type");const noteMime = useNoteProperty(note, "mime");const [ highlightsList ] = useTriliumOptionJson<string[]>("highlightsList");+ // Subscribe to the AI toggle so the LLM sidebar is added/removed reactively without a page reload.+ const [ aiEnabled ] = useTriliumOptionBool("aiEnabled");const isPdf = noteType === "file" && noteMime === "application/pdf";if (!rightPaneVisible) return [];@@ -102,7 +104,7 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent) {// Loaded lazily because the chat pulls in the whole LLM + CKEditor graph,// which users without the LLM experimental feature should never download.el: <LazyComponent loader={() => import("./SidebarChat.jsx")} />,- enabled: noteType !== "llmChat" && isExperimentalFeatureEnabled("llm"),+ enabled: noteType !== "llmChat" && !isStandalone && aiEnabled,position: 1000},...widgetsByParent.getLegacyWidgets("right-pane").map((widget) => ({