mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 23:18:46 +08:00
chore(react/type_widgets): get LLM note to load
This commit is contained in:
parent
22f8929da6
commit
cebb54ddf6
1 changed files with 22 additions and 14 deletions
|
@ -4,14 +4,30 @@ import { type TypeWidgetProps } from "./type_widget";
|
||||||
import LlmChatPanel from "../llm_chat";
|
import LlmChatPanel from "../llm_chat";
|
||||||
|
|
||||||
export default function AiChat({ note, noteContext }: TypeWidgetProps) {
|
export default function AiChat({ note, noteContext }: TypeWidgetProps) {
|
||||||
const dataRef = useRef<string>();
|
const dataRef = useRef<object>();
|
||||||
const spacedUpdate = useEditorSpacedUpdate({
|
const spacedUpdate = useEditorSpacedUpdate({
|
||||||
note,
|
note,
|
||||||
getData: async () => dataRef.current,
|
getData: async () => ({
|
||||||
onContentChange: (newContent) => dataRef.current = newContent
|
content: JSON.stringify(dataRef.current)
|
||||||
|
}),
|
||||||
|
onContentChange: (newContent) => {
|
||||||
|
try {
|
||||||
|
dataRef.current = JSON.parse(newContent);
|
||||||
|
} catch (e) {
|
||||||
|
dataRef.current = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const [ ChatWidget, llmChatPanel ] = useLegacyWidget(() => {
|
const [ ChatWidget, llmChatPanel ] = useLegacyWidget(() => {
|
||||||
return new LlmChatPanel();
|
const llmChatPanel = new LlmChatPanel();
|
||||||
|
llmChatPanel.setDataCallbacks(
|
||||||
|
async (data) => {
|
||||||
|
dataRef.current = data;
|
||||||
|
spacedUpdate.scheduleUpdate();
|
||||||
|
},
|
||||||
|
async () => dataRef.current
|
||||||
|
);
|
||||||
|
return llmChatPanel;
|
||||||
}, {
|
}, {
|
||||||
noteContext,
|
noteContext,
|
||||||
containerClassName: "ai-chat-widget-container",
|
containerClassName: "ai-chat-widget-container",
|
||||||
|
@ -21,17 +37,9 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) {
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
llmChatPanel.setDataCallbacks(
|
llmChatPanel.setNoteId(note.noteId);
|
||||||
async (data) => {
|
|
||||||
dataRef.current = data;
|
|
||||||
spacedUpdate.scheduleUpdate();
|
|
||||||
},
|
|
||||||
async () => dataRef.current
|
|
||||||
);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
llmChatPanel.setCurrentNoteId(note.noteId);
|
llmChatPanel.setCurrentNoteId(note.noteId);
|
||||||
|
llmChatPanel.refresh();
|
||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
return ChatWidget;
|
return ChatWidget;
|
||||||
|
|
Loading…
Add table
Reference in a new issue