//import { signal, computed, useSignal } from "@preact/signals"; import { signal } from "@preact-signals/safe-react"; import { withTrackSignals } from "@preact-signals/safe-react/manual"; import { CommentBlockData, RenderBody } from "editorjs-comment"; interface Comment { commentBlockId: string; blockId: string; content: string //... your custom fields } const comments = signal([]); const commentSignal = signal(Object()); const RenderItem = ({ commentBlockId, blockId, onClose, addCommentBlockData, }: RenderBody) => { commentSignal.value = { ...Object(), commentBlockId, blockId, }; const data = (value: string) => { commentSignal.value = { ...commentSignal.value, content: value }; }; //save comment to DB const saveComment = () => { addContractCommentApi({ ...commentSignal.value, }).then((respo) => { if (respo.length > 0) { const data = { id: respo[0].commentBlockId, count: respo.length, }; // if the data is save to the database then call the setCommentBlockData method // for every new comment section this should be call, it will highlight the selected section with marker and also add the required data to the block. // this can be called only once for a new comment section if (addCommentBlockData) { addCommentBlockData(data); } comments.value = respo; } }); }; //The commentBlockId for the current comment section is available to be use to query the db, depending on your logic const getComments = () => { if (!commentBlockId) { comments.value = []; return; } getContractCommentByIdApi(commentBlockId) .then((respon) => { if (respon.length > 0) { addCommentBlockData({ id: respon[0].commentBlockId, count: respon.length, }); comments.value = respon; } }) .catch((err) => { comments.value = []; console.log(err); }); }; getComments(); // manually render on change const ShowComments = withTrackSignals(() => { return (
{comments.value.map((comment, index) => (
{comment.}
))}
); }); const closeEl = () => { if (!onClose) return; onClose(); }; return (
{text.value}
); }; export default RenderItem;