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
chore(react/type_widgets): get LLM note to load
Elian Dorancebb54ddf6ac
diff --git a/apps/client/src/widgets/type_widgets/AiChat.tsx b/apps/client/src/widgets/type_widgets/AiChat.tsxindex 49ab7267a9..50e060e2dc 100644--- a/apps/client/src/widgets/type_widgets/AiChat.tsx+++ b/apps/client/src/widgets/type_widgets/AiChat.tsx@@ -4,23 +4,22 @@ import { type TypeWidgetProps } from "./type_widget";import LlmChatPanel from "../llm_chat";export default function AiChat({ note, noteContext }: TypeWidgetProps) {- const dataRef = useRef<string>();+ const dataRef = useRef<object>();const spacedUpdate = useEditorSpacedUpdate({note,- getData: async () => dataRef.current,- onContentChange: (newContent) => dataRef.current = newContent- });- const [ ChatWidget, llmChatPanel ] = useLegacyWidget(() => {- return new LlmChatPanel();- }, {- noteContext,- containerClassName: "ai-chat-widget-container",- containerStyle: {- height: "100%"+ getData: async () => ({+ content: JSON.stringify(dataRef.current)+ }),+ onContentChange: (newContent) => {+ try {+ dataRef.current = JSON.parse(newContent);+ } catch (e) {+ dataRef.current = {};+ }}});-- useEffect(() => {+ const [ ChatWidget, llmChatPanel ] = useLegacyWidget(() => {+ const llmChatPanel = new LlmChatPanel();llmChatPanel.setDataCallbacks(async (data) => {dataRef.current = data;@@ -28,10 +27,19 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) {},async () => dataRef.current);- }, []);+ return llmChatPanel;+ }, {+ noteContext,+ containerClassName: "ai-chat-widget-container",+ containerStyle: {+ height: "100%"+ }+ });useEffect(() => {+ llmChatPanel.setNoteId(note.noteId);llmChatPanel.setCurrentNoteId(note.noteId);+ llmChatPanel.refresh();}, [ note ]);return ChatWidget;