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

This commit is contained in:
Elian Doran
2025-10-05 14:15:51 +03:00
parent cebb54ddf6
commit b0c984decd
2 changed files with 2 additions and 49 deletions

View File

@@ -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;

View File

@@ -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;
}
}
}