mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-11 19:44:00 -06:00
chore(react/type_widgets): fix refresh on first start
This commit is contained in:
parent
cebb54ddf6
commit
b0c984decd
@ -13,6 +13,7 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) {
|
|||||||
onContentChange: (newContent) => {
|
onContentChange: (newContent) => {
|
||||||
try {
|
try {
|
||||||
dataRef.current = JSON.parse(newContent);
|
dataRef.current = JSON.parse(newContent);
|
||||||
|
llmChatPanel.refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dataRef.current = {};
|
dataRef.current = {};
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
llmChatPanel.setNoteId(note.noteId);
|
llmChatPanel.setNoteId(note.noteId);
|
||||||
llmChatPanel.setCurrentNoteId(note.noteId);
|
llmChatPanel.setCurrentNoteId(note.noteId);
|
||||||
llmChatPanel.refresh();
|
console.log("Refresh!");
|
||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
return ChatWidget;
|
return ChatWidget;
|
||||||
|
|||||||
@ -181,52 +181,4 @@ export default class AiChatTypeWidget extends TypeWidget {
|
|||||||
toastService.showError("Failed to save chat data");
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user