Skip to content
Snippets Groups Projects
Commit 594d4e79 authored by chris's avatar chris
Browse files

active comment in progress

parent 307cad14
No related branches found
No related tags found
2 merge requests!548Merge yjs with standard comments,!545Overlapping comments
......@@ -66,7 +66,7 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
useEffect(() => {
setIsActive(false);
recalculateTops();
if (activeComment && commentId === activeComment.attrs.id) {
if (activeComment && commentId === activeComment.id) {
setIsActive(true);
recalculateTops();
}
......
......@@ -58,7 +58,7 @@ export default ({ area, users }) => {
let isActive = false;
if (
(activeComment && id === activeComment.attrs.id) ||
(activeComment && id === activeComment.id) ||
(activeTrackChange && id === activeTrackChange.attrs.id)
)
isActive = true;
......@@ -247,7 +247,7 @@ const updateMarks = (views, comments) => {
groupedMarkNodes.main = groupedMarkNodes.main.concat(newComments.main);
if (newComments?.notes?.length > 0)
groupedMarkNodes.notes = groupedMarkNodes.notes.concat(newComments.notes);
console.log(sortBy(groupedMarkNodes.main, ['from']));
return {
main: sortBy(groupedMarkNodes.main, ['from']),
notes: groupedMarkNodes.notes,
......
......@@ -37,6 +37,8 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
},
}),
);
dispatch(state.tr);
// Delete when new comments are done
// Commands.createComment(state, dispatch, group, activeViewId);
// activeView.focus();
};
......
......@@ -7,74 +7,32 @@ import { DocumentHelpers } from 'wax-prosemirror-core';
const commentPlugin = new PluginKey('commentPlugin');
const getComment = state => {
const commentMark = state.schema.marks.comment;
const commentOnSelection = DocumentHelpers.findFragmentedMark(
state,
commentMark,
);
// Don't allow Active comment if selection is not collapsed
if (
state.selection.from !== state.selection.to &&
commentOnSelection &&
commentOnSelection.attrs.conversation.length
) {
return;
}
if (commentOnSelection) {
const commentNodes = DocumentHelpers.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);
}
});
});
const minPos = minBy(allCommentsWithSameId, 'pos');
const maxPos = maxBy(allCommentsWithSameId, 'pos');
if (
state.selection.from ===
maxPos.pos + last(allCommentsWithSameId).node.nodeSize
) {
state.schema.marks.comment.spec.inclusive = false;
} else {
state.schema.marks.comment.spec.inclusive = true;
}
if (allCommentsWithSameId.length > 1) {
return {
from: minPos.pos,
to: maxPos.pos + last(allCommentsWithSameId).node.nodeSize,
attrs: commentOnSelection.attrs,
contained: commentOnSelection.contained,
};
}
}
return commentOnSelection;
const getComment = (state, context) => {
const {
options: { comments },
} = context;
if (!comments?.length) return;
console.log('sds', comments);
return {
from: comments[0].from,
to: comments[0].to,
attrs: comments[0].data,
id: comments[0].id,
// contained: commentOnSelection.contained,
};
};
c;
export default (key, context) => {
return new Plugin({
key: commentPlugin,
state: {
init: (_, state) => {
return { comment: getComment(state) };
return { comment: getComment(state, context) };
},
apply(tr, prev, _, newState) {
console.log(context);
const comment = getComment(newState);
const comment = getComment(newState, context);
let createDecoration;
if (comment) {
createDecoration = DecorationSet.create(newState.doc, [
......
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