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 }) => { ...@@ -66,7 +66,7 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
useEffect(() => { useEffect(() => {
setIsActive(false); setIsActive(false);
recalculateTops(); recalculateTops();
if (activeComment && commentId === activeComment.attrs.id) { if (activeComment && commentId === activeComment.id) {
setIsActive(true); setIsActive(true);
recalculateTops(); recalculateTops();
} }
......
...@@ -58,7 +58,7 @@ export default ({ area, users }) => { ...@@ -58,7 +58,7 @@ export default ({ area, users }) => {
let isActive = false; let isActive = false;
if ( if (
(activeComment && id === activeComment.attrs.id) || (activeComment && id === activeComment.id) ||
(activeTrackChange && id === activeTrackChange.attrs.id) (activeTrackChange && id === activeTrackChange.attrs.id)
) )
isActive = true; isActive = true;
...@@ -247,7 +247,7 @@ const updateMarks = (views, comments) => { ...@@ -247,7 +247,7 @@ const updateMarks = (views, comments) => {
groupedMarkNodes.main = groupedMarkNodes.main.concat(newComments.main); groupedMarkNodes.main = groupedMarkNodes.main.concat(newComments.main);
if (newComments?.notes?.length > 0) if (newComments?.notes?.length > 0)
groupedMarkNodes.notes = groupedMarkNodes.notes.concat(newComments.notes); groupedMarkNodes.notes = groupedMarkNodes.notes.concat(newComments.notes);
console.log(sortBy(groupedMarkNodes.main, ['from']));
return { return {
main: sortBy(groupedMarkNodes.main, ['from']), main: sortBy(groupedMarkNodes.main, ['from']),
notes: groupedMarkNodes.notes, notes: groupedMarkNodes.notes,
......
...@@ -37,6 +37,8 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -37,6 +37,8 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
}, },
}), }),
); );
dispatch(state.tr);
// Delete when new comments are done
// Commands.createComment(state, dispatch, group, activeViewId); // Commands.createComment(state, dispatch, group, activeViewId);
// activeView.focus(); // activeView.focus();
}; };
......
...@@ -7,74 +7,32 @@ import { DocumentHelpers } from 'wax-prosemirror-core'; ...@@ -7,74 +7,32 @@ import { DocumentHelpers } from 'wax-prosemirror-core';
const commentPlugin = new PluginKey('commentPlugin'); const commentPlugin = new PluginKey('commentPlugin');
const getComment = state => { const getComment = (state, context) => {
const commentMark = state.schema.marks.comment; const {
const commentOnSelection = DocumentHelpers.findFragmentedMark( options: { comments },
state, } = context;
commentMark, if (!comments?.length) return;
); console.log('sds', comments);
// Don't allow Active comment if selection is not collapsed return {
if ( from: comments[0].from,
state.selection.from !== state.selection.to && to: comments[0].to,
commentOnSelection && attrs: comments[0].data,
commentOnSelection.attrs.conversation.length id: comments[0].id,
) { // contained: commentOnSelection.contained,
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;
}; };
c;
export default (key, context) => { export default (key, context) => {
return new Plugin({ return new Plugin({
key: commentPlugin, key: commentPlugin,
state: { state: {
init: (_, state) => { init: (_, state) => {
return { comment: getComment(state) }; return { comment: getComment(state, context) };
}, },
apply(tr, prev, _, newState) { apply(tr, prev, _, newState) {
console.log(context); const comment = getComment(newState, context);
const comment = getComment(newState);
let createDecoration; let createDecoration;
if (comment) { if (comment) {
createDecoration = DecorationSet.create(newState.doc, [ 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