mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
chore(react/type_widgets): fix refresh on first start
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user