Skip to content
Snippets Groups Projects
Commit 734c3e0e authored by chris's avatar chris
Browse files

remove/resolve comment

parent 64a926f0
No related branches found
No related tags found
2 merge requests!548Merge yjs with standard comments,!545Overlapping comments
......@@ -33,6 +33,7 @@ export default class CommentsService extends Service {
...items,
]);
commentsConfig.getComments(this.allCommentsFromStates);
this.app.context.setOption({ comments: this.allCommentsFromStates });
},
onAnnotationListChange: () => true,
......
......@@ -7,6 +7,7 @@ import styled from 'styled-components';
import { WaxContext, DocumentHelpers, Commands } from 'wax-prosemirror-core';
import { override } from '@pubsweet/ui-toolkit';
import CommentBox from './ui/comments/CommentBox';
import { AnnotationPluginKey } from '../plugins/AnnotationPlugin';
const ConnectedCommentStyled = styled.div`
margin-left: ${props => (props.active ? `${-20}px` : `${50}px`)};
......@@ -33,6 +34,7 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
app,
activeView,
activeViewId,
options: { comments },
} = context;
const [isActive, setIsActive] = useState(false);
......@@ -41,8 +43,6 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
const { state, dispatch } = activeView;
const { viewId, conversation } = comment.data;
const commentMark = state.schema.marks.comment;
const styles = {
top: `${top}px`,
};
......@@ -106,36 +106,27 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
};
const onClickResolve = () => {
let maxPos = comment.pos;
let minPos = comment.pos;
allCommentsWithSameId.forEach(singleComment => {
const markPosition = DocumentHelpers.findMarkPosition(
state,
singleComment.pos,
'comment',
);
if (markPosition.from < minPos) minPos = markPosition.from;
if (markPosition.to > maxPos) maxPos = markPosition.to;
});
// if (allCommentsWithSameId.length > 1);
// maxPos += last(allCommentsWithSameId).node.nodeSize;
dispatch(
state.tr.setMeta(AnnotationPluginKey, {
type: 'deleteComment',
id: activeComment.id,
}),
);
recalculateTops();
dispatch(state.tr.removeMark(minPos, maxPos, commentMark));
activeView.focus();
setTimeout(() => {
const newComments = comments.filter(comm => {
return comm.id !== activeComment.id;
});
context.setOption({ comments: newComments });
});
};
const onTextAreaBlur = () => {
// TODO Save into local storage
// if (content !== '') {
// onClickPost(content);
// }
setTimeout(() => {
if (conversation.length === 0 && !clickPost) {
// onClickResolve();
activeView.focus();
}
}, 400);
if (conversation.length === 0 && !clickPost) {
onClickResolve();
activeView.focus();
}
};
const MemorizedComponent = useMemo(
......
/* eslint react/prop-types: 0 */
import React, { useLayoutEffect, useContext } from 'react';
import { WaxContext, Commands, DocumentHelpers } from 'wax-prosemirror-core';
import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core';
import CommentBubble from './CommentBubble';
import { AnnotationPluginKey } from '../../../plugins/AnnotationPlugin';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment