import { Editor } from "@tiptap/core" import React, { useEffect, useRef, useState } from "react"; import { AdviceManager } from "@/editor/extensions/advice/advice-manager"; import { Advice } from "@/editor/extensions/advice/advice"; import { MarkdownParser } from '@/../node_modules/tiptap-markdown/src/parse/MarkdownParser'; export interface AdviceViewProps { editor: Editor } // based on : https://github.com/sereneinserenade/tiptap-comment-extension/blob/d8ad0d01e98ac416e69f27ab237467b782076c16/demos/react/src/components/Tiptap.tsx export const AdviceView = ({ editor }: AdviceViewProps) => { const [advices, setAdvices] = useState([]) const [activeCommentId, setActiveId] = useState(null) const advicesSectionRef = useRef(null) const focusAdviceWithActiveId = (id: string) => { if (!advicesSectionRef.current) return const adviceInput = advicesSectionRef.current.querySelector(`p#${id}`) if (!adviceInput) return adviceInput.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' }) } useEffect(() => { AdviceManager.getInstance().on('add', (advice) => { setAdvices(AdviceManager.getInstance().getAdvices()); setActiveId(advice.id); setTimeout(() => { focusAdviceWithActiveId(advice.id); }); }); AdviceManager.getInstance().on('remove', (advice) => { setAdvices(AdviceManager.getInstance().getAdvices()); }); AdviceManager.getInstance().onActiveIdChange((id) => { setActiveId(id); setTimeout(() => { focusAdviceWithActiveId(id); }); }); }, []); return
{advices.length ? (advices.map(advice => (
AI Assistant {advice.createdAt.toLocaleDateString()}

{advice.content || ''}

)) ) : (No advices yet) }
}