Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widgets): fix refresh on first start

Elian Doranb0c984decdb0
diff --git a/apps/client/src/widgets/type_widgets/AiChat.tsx b/apps/client/src/widgets/type_widgets/AiChat.tsx
index 50e060e2dc..81da5355d8 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 314ab824f5..d7220d9c6b 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;
- }
- }
}