Newer
Older
import React, { useState, useRef } from 'react';
import { v4 as uuidv4 } from 'uuid';
import styled from 'styled-components';
import { WaxContext } from 'wax-prosemirror-core';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
const SinlgeCommentRow = styled.div`
padding: 4px;
border-bottom: 1px solid #ffab20;
`;
export default ({ comment, activeView, user }) => {
const commentInput = useRef(null);
const [commentAnnotation, setCommentAnnotation] = useState(comment);
const [commentInputValue, setcommentInputValue] = useState('');
const commentMark = state.schema.marks.comment;
saveComment();
}
};
const saveComment = () => {
const { tr, doc } = state;
const obj = { [user.username]: value };
commentAnnotation.attrs.conversation.push(obj);
const allComments = DocumentHelpers.findAllCommentsWithSameId(state);
allComments.forEach(singleComment => {
dispatch(
tr.addMark(
singleComment.pos,
singleComment.pos + singleComment.nodeSize,
commentMark.create({
...((commentAnnotation && commentAnnotation.attrs) || {}),
conversation: commentAnnotation.attrs.conversation,
}),
),
const onBlur = () => {
const {
current: { value },
} = commentInput;
if (value !== '') {
}
if (conversation.length === 0 && value === '') {
const commentPosition = DocumentHelpers.findMarkPosition(activeView, comment.pos, 'comment');
dispatch(state.tr.removeMark(commentPosition.from, commentPosition.to, commentMark));
const commentPosition = DocumentHelpers.findMarkPosition(activeView, comment.pos, 'comment');
dispatch(state.tr.removeMark(commentPosition.from, commentPosition.to, commentMark));
<input
type="text"
ref={commentInput}
placeholder="add a new comment"
onChange={updateCommentInputValue}
onKeyPress={handleKeyDown}
onClick={event => {
event.stopPropagation();
}}
<button type="button" onClick={saveComment}>
Post
</button>
<button type="button" onClick={resolveComment}>
Resolve
</button>
<SinlgeCommentRow key={uuidv4()}>{`${user.username} : ${singleComment[user.username]}`}</SinlgeCommentRow>