From cebb54ddf6acb7382ec9e3425550d9a401ccd0aa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 5 Oct 2025 12:40:55 +0300 Subject: [PATCH] chore(react/type_widgets): get LLM note to load --- .../src/widgets/type_widgets/AiChat.tsx | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/AiChat.tsx b/apps/client/src/widgets/type_widgets/AiChat.tsx index 49ab7267a..50e060e2d 100644 --- a/apps/client/src/widgets/type_widgets/AiChat.tsx +++ b/apps/client/src/widgets/type_widgets/AiChat.tsx @@ -4,14 +4,30 @@ import { type TypeWidgetProps } from "./type_widget"; import LlmChatPanel from "../llm_chat"; export default function AiChat({ note, noteContext }: TypeWidgetProps) { - const dataRef = useRef(); + const dataRef = useRef(); const spacedUpdate = useEditorSpacedUpdate({ note, - getData: async () => dataRef.current, - onContentChange: (newContent) => dataRef.current = newContent + getData: async () => ({ + content: JSON.stringify(dataRef.current) + }), + onContentChange: (newContent) => { + try { + dataRef.current = JSON.parse(newContent); + } catch (e) { + dataRef.current = {}; + } + } }); const [ ChatWidget, llmChatPanel ] = useLegacyWidget(() => { - return new LlmChatPanel(); + const llmChatPanel = new LlmChatPanel(); + llmChatPanel.setDataCallbacks( + async (data) => { + dataRef.current = data; + spacedUpdate.scheduleUpdate(); + }, + async () => dataRef.current + ); + return llmChatPanel; }, { noteContext, containerClassName: "ai-chat-widget-container", @@ -21,17 +37,9 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) { }); useEffect(() => { - llmChatPanel.setDataCallbacks( - async (data) => { - dataRef.current = data; - spacedUpdate.scheduleUpdate(); - }, - async () => dataRef.current - ); - }, []); - - useEffect(() => { + llmChatPanel.setNoteId(note.noteId); llmChatPanel.setCurrentNoteId(note.noteId); + llmChatPanel.refresh(); }, [ note ]); return ChatWidget;