diff --git a/wax-prosemirror-services/src/CommentsService/components/RightArea.js b/wax-prosemirror-services/src/CommentsService/components/RightArea.js index 6cbd3035b0410f93a534c1a3fd72af0d08826ce6..f997f99c4ed747edfdc42f1bcae11d54db36d40a 100644 --- a/wax-prosemirror-services/src/CommentsService/components/RightArea.js +++ b/wax-prosemirror-services/src/CommentsService/components/RightArea.js @@ -177,14 +177,26 @@ export default ({ area, users }) => { }; useDeepCompareEffect(() => { - setMarksNodes( - updateMarks( - pmViews, - CommentDecorationPluginKey?.getState( - activeView.state, - )?.allCommentsDataList(), - ), - ); + if (app.config.get('config.YjsService')) { + setMarksNodes( + updateMarks( + pmViews, + CommentDecorationPluginKey?.getState( + activeView.state, + )?.allCommentsDataList(), + ), + ); + } else { + setMarksNodes( + updateMarks( + pmViews, + CommentDecorationPluginKey?.getState( + activeView.state, + )?.allCommentsList(), + ), + ); + } + let firstRunTimeout = () => true; if (isFirstRun) { firstRunTimeout = setTimeout(() => { diff --git a/wax-prosemirror-services/src/CommentsService/plugins/CommentPlugin.js b/wax-prosemirror-services/src/CommentsService/plugins/CommentPlugin.js index c821a2ea488fc66454a75db828edd03921a11428..3c1ebb8e49c6d6e736de3a35f30fe567b4dd3ed1 100644 --- a/wax-prosemirror-services/src/CommentsService/plugins/CommentPlugin.js +++ b/wax-prosemirror-services/src/CommentsService/plugins/CommentPlugin.js @@ -7,7 +7,6 @@ import { CommentDecorationPluginKey } from './CommentDecorationPlugin'; const commentPlugin = new PluginKey('commentPlugin'); const getComment = (state, app) => { - if (!app.config.get('config.YjsService')) return getCommentNonYjs(state, app); const { context } = app; const commentsMap = CommentDecorationPluginKey.getState(state).getMap(); const commentsDataMap = CommentDecorationPluginKey.getState( @@ -24,6 +23,10 @@ const getComment = (state, app) => { } }); + if (!app.config.get('config.YjsService')) { + return getCommentNonYjs(commentData, state, context); + } + commentData = sortBy(commentData, ['data.pmFrom']); if (commentData.length > 0) { @@ -44,8 +47,23 @@ const getComment = (state, app) => { return undefined; }; -const getCommentNonYjs = (state, app) => { - console.log('non yjs active'); +const getCommentNonYjs = (comments, state, context) => { + const commentData = sortBy(comments, ['from']); + + if (commentData.length > 0) { + if ( + (state.selection.from !== state.selection.to && + last(commentData)?.data?.conversation.length === 0) || + (state.selection.from === state.selection.to && + last(commentData)?.data?.conversation.length !== 0) + ) { + context.setOption({ activeComment: last(commentData) }); + return last(commentData); + } + return undefined; + } + + return undefined; }; export default (key, app) => {