Skip to content
Snippets Groups Projects
Commit 847d3b32 authored by chris's avatar chris
Browse files

fix comment on note creation

parent c684fb29
No related branches found
No related tags found
1 merge request!521Fix comments
......@@ -128,7 +128,7 @@ const isOnSameTextBlock = state => {
return false;
};
const createComment = (state, dispatch, group, viewid) => {
const createComment = (state, dispatch, group, viewid, conversation = []) => {
const {
selection: { $from, $to },
tr,
......@@ -147,20 +147,38 @@ const createComment = (state, dispatch, group, viewid) => {
footnoteNode.content.size + 2 ===
state.selection.to - state.selection.from
) {
return createCommentOnSingleFootnote(state, dispatch, group, viewid);
return createCommentOnSingleFootnote(
state,
dispatch,
group,
viewid,
conversation,
);
}
return createCommentOnFootnote(state, dispatch, group, viewid);
return createCommentOnFootnote(
state,
dispatch,
group,
viewid,
conversation,
);
}
toggleMark(state.config.schema.marks.comment, {
id: uuidv4(),
group,
conversation: [],
conversation,
viewid,
})(state, dispatch);
};
const createCommentOnSingleFootnote = (state, dispatch, group, viewid) => {
const createCommentOnSingleFootnote = (
state,
dispatch,
group,
viewid,
conversation,
) => {
const { tr } = state;
tr.step(
new AddMarkStep(
......@@ -169,15 +187,21 @@ const createCommentOnSingleFootnote = (state, dispatch, group, viewid) => {
state.config.schema.marks.comment.create({
id: uuidv4(),
group,
conversation: [],
conversation,
viewid,
}),
),
);
).setMeta('forceUpdate', true);
dispatch(tr);
};
const createCommentOnFootnote = (state, dispatch, group, viewid) => {
const createCommentOnFootnote = (
state,
dispatch,
group,
viewid,
conversation,
) => {
const {
selection: { $from },
selection,
......@@ -231,11 +255,11 @@ const createCommentOnFootnote = (state, dispatch, group, viewid) => {
state.config.schema.marks.comment.create({
id,
group,
conversation: [],
conversation,
viewid,
}),
),
);
).setMeta('forceUpdate', true);
});
dispatch(tr);
......
......@@ -4,7 +4,7 @@ import React, { useContext, useMemo, useState, useEffect } from 'react';
import { TextSelection } from 'prosemirror-state';
import { last, maxBy } from 'lodash';
import styled from 'styled-components';
import { WaxContext, DocumentHelpers } from 'wax-prosemirror-core';
import { WaxContext, DocumentHelpers, Commands } from 'wax-prosemirror-core';
import { v4 as uuidv4 } from 'uuid';
import { override } from '@pubsweet/ui-toolkit';
import CommentBox from './ui/comments/CommentBox';
......@@ -48,7 +48,6 @@ export default ({ comment, top, commentId, recalculateTops }) => {
comment,
);
}
const commentMark = state.schema.marks.comment;
const styles = {
......@@ -92,23 +91,29 @@ export default ({ comment, top, commentId, recalculateTops }) => {
commentMark,
),
);
activeView.dispatch(
activeView.state.tr
.addMark(
singleComment.pos,
singleComment.pos + singleComment.node.nodeSize,
commentMark.create({
id,
group: comment.attrs.group,
viewid: comment.attrs.viewid,
conversation: comment.attrs.conversation,
title: comment.attrs.title,
}),
)
.setMeta('forceUpdate', true),
);
// activeView.dispatch(
// activeView.state.tr
// .addMark(
// singleComment.pos,
// singleComment.pos + singleComment.node.nodeSize,
// commentMark.create({
// id,
// group: comment.attrs.group,
// viewid: comment.attrs.viewid,
// conversation: comment.attrs.conversation,
// title: comment.attrs.title,
// }),
// )
// .setMeta('forceUpdate', true),
// );
});
Commands.createComment(
activeView.state,
activeView.dispatch,
comment.attrs.group,
comment.attrs.viewid,
comment.attrs.conversation,
);
activeView.focus();
recalculateTops();
};
......
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