Skip to content
Snippets Groups Projects
Commit 5e38c112 authored by chris's avatar chris
Browse files

save on fragmented comment

parent 17a1657c
No related branches found
No related tags found
1 merge request!119Comment service
This commit is part of merge request !119. Comments created here will be created in the context of that merge request.
......@@ -37,18 +37,21 @@ export default ({ comment, activeView, user }) => {
const obj = { [user.username]: value };
commentAnnotation.attrs.conversation.push(obj);
const actualComment = DocumentHelpers.findMark(state, commentMark);
dispatch(
tr.addMark(
actualComment.from,
actualComment.to,
commentMark.create({
...((commentAnnotation && commentAnnotation.attrs) || {}),
conversation: commentAnnotation.attrs.conversation
})
)
);
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
})
)
);
});
setcommentInputValue("");
};
......
const findMark = (state, PMmark, toArr = false) => {
const { selection: { $from, $to }, doc } = state;
const fromMark = $from.marks().find(mark => mark.type === PMmark);
const toMark = $to.marks().find(mark => mark.type === PMmark);
let markFound;
......@@ -72,6 +71,27 @@ const findFragmentedMark = (state, PMmark) => {
return markFound;
};
const findAllCommentsWithSameId = state => {
const commentMark = state.schema.marks["comment"];
const commentOnSelection = findFragmentedMark(state, commentMark);
const commentNodes = findChildrenByMark(state.doc, commentMark, true);
const allCommentsWithSameId = [];
commentNodes.map(node => {
node.node.marks.filter(mark => {
if (
mark.type.name === "comment" &&
commentOnSelection.attrs.id === mark.attrs.id
) {
allCommentsWithSameId.push(node);
}
});
});
console.log(allCommentsWithSameId);
return allCommentsWithSameId;
};
export const flatten = (node, descend = true) => {
if (!node) {
throw new Error('Invalid "node" parameter');
......@@ -123,5 +143,6 @@ export default {
findChildrenByMark,
findChildrenByAttr,
getSelectionMark,
findFragmentedMark
findFragmentedMark,
findAllCommentsWithSameId
};
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