fundon
2024-06-25 15:56:44 +00:00
parent cffaf815e1
commit a92515b5aa
9 changed files with 114 additions and 65 deletions
@@ -4,6 +4,7 @@ export type SidebarTabName = 'outline' | 'frame' | 'chat' | 'journal';
export interface SidebarTabProps {
editor: AffineEditorContainer | null;
onLoad: ((component: HTMLElement) => void) | null;
}
export interface SidebarTab {
@@ -7,7 +7,7 @@ import type { SidebarTab, SidebarTabProps } from '../sidebar-tab';
import * as styles from './chat.css';
// A wrapper for CopilotPanel
const EditorChatPanel = ({ editor }: SidebarTabProps) => {
const EditorChatPanel = ({ editor, onLoad }: SidebarTabProps) => {
const chatPanelRef = useRef<ChatPanel | null>(null);
const onRefChange = useCallback((container: HTMLDivElement | null) => {
@@ -17,6 +17,16 @@ const EditorChatPanel = ({ editor }: SidebarTabProps) => {
}
}, []);
useEffect(() => {
if (onLoad && chatPanelRef.current) {
(chatPanelRef.current as ChatPanel).updateComplete
.then(() => {
onLoad(chatPanelRef.current as HTMLElement);
})
.catch(console.error);
}
}, [onLoad]);
useEffect(() => {
if (!editor) return;
const pageService = editor.host.spec.getService('affine:page');