From b0c984decdb0f0a5304f09d55a1e6b0628d5c3a0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 5 Oct 2025 14:15:51 +0300 Subject: [PATCH] chore(react/type_widgets): fix refresh on first start --- .../src/widgets/type_widgets/AiChat.tsx | 3 +- .../src/widgets/type_widgets_old/ai_chat.ts | 48 ------------------- 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/AiChat.tsx b/apps/client/src/widgets/type_widgets/AiChat.tsx index 50e060e2d..81da5355d 100644 --- a/apps/client/src/widgets/type_widgets/AiChat.tsx +++ b/apps/client/src/widgets/type_widgets/AiChat.tsx @@ -13,6 +13,7 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) { onContentChange: (newContent) => { try { dataRef.current = JSON.parse(newContent); + llmChatPanel.refresh(); } catch (e) { dataRef.current = {}; } @@ -39,7 +40,7 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) { useEffect(() => { llmChatPanel.setNoteId(note.noteId); llmChatPanel.setCurrentNoteId(note.noteId); - llmChatPanel.refresh(); + console.log("Refresh!"); }, [ note ]); return ChatWidget; diff --git a/apps/client/src/widgets/type_widgets_old/ai_chat.ts b/apps/client/src/widgets/type_widgets_old/ai_chat.ts index 314ab824f..d7220d9c6 100644 --- a/apps/client/src/widgets/type_widgets_old/ai_chat.ts +++ b/apps/client/src/widgets/type_widgets_old/ai_chat.ts @@ -181,52 +181,4 @@ export default class AiChatTypeWidget extends TypeWidget { toastService.showError("Failed to save chat data"); } } - - // Get data from the note - async getData() { - if (!this.note) { - return null; - } - - try { - console.log(`AiChatTypeWidget: Getting data for note ${this.note.noteId}`); - const content = await this.note.getContent(); - - if (!content) { - console.log("Note content is empty"); - return null; - } - - // Parse the content as JSON - let parsedContent; - try { - parsedContent = JSON.parse(content as string); - console.log("Successfully parsed note content as JSON"); - } catch (e) { - console.error("Error parsing chat content as JSON:", e); - return null; - } - - // Check if this is a blob response with 'content' property that needs to be parsed again - // This happens when the content is returned from the /blob endpoint - if (parsedContent.content && typeof parsedContent.content === 'string' && - parsedContent.blobId && parsedContent.contentLength) { - try { - // The actual chat data is inside the 'content' property as a string - console.log("Detected blob response structure, parsing inner content"); - const innerContent = JSON.parse(parsedContent.content); - console.log("Successfully parsed blob inner content"); - return innerContent; - } catch (innerError) { - console.error("Error parsing inner blob content:", innerError); - return null; - } - } - - return parsedContent; - } catch (e) { - console.error("Error loading AI Chat data:", e); - return null; - } - } }