Skip to content
Snippets Groups Projects
Commit 6315e975 authored by chris's avatar chris
Browse files

save conversation on mark

parent c6c97199
No related branches found
No related tags found
1 merge request!109Track changes ids
......@@ -47,7 +47,7 @@ const Editoria = () => (
autoFocus
placeholder="Type Something..."
fileUpload={file => renderImage(file)}
value={`<p class="paragraph">This is the first paragraph</p><p class="paragraph">This is the second paragraph</p><p class="author">This is an author</p>`}
value={`<p class="paragraph">This is the first paragraph</p><p class="paragraph">This is the <span class="comment" data-id="ff7552b8-956c-4822-99b5-826715751c45" data-conversation="[{&quot;demo&quot;:&quot;dsdadsa&quot;}]" data-group="main">second</span> paragraph</p><p class="author">This is an author</p>`}
// value={`<p class="paragraph"><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">and a </span><span class="insertion" data-id="" data-user="1234" data-username="demo" data-date="26541557" data-group=""><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">sdasdssd</span></span><span class="comment" data-id="834ba3c5-1fcf-4a42-8e2f-1f975f229716" data-conversation="[]" data-group="main">paragraph</span></p><p class="paragraph">more</p>`}
layout={EditoriaLayout}
TrackChange
......
......@@ -37,6 +37,7 @@ export default ({ comment, view, top, dataBox }) => {
const { view: { main: { props: { user } } }, app, activeView } = useContext(
WaxContext
),
{ state, dispatch } = activeView,
commentInput = useRef(null),
[animate, setAnimate] = useState(false),
[commentAnnotation, setCommentAnnotation] = useState(comment),
......@@ -59,7 +60,22 @@ export default ({ comment, view, top, dataBox }) => {
const saveComment = () => {
const { current: { value } } = commentInput;
console.log(commentAnnotation, currentUser, value);
const { tr, doc } = state;
const commentMark = state.schema.marks.comment;
const obj = { [user.username]: value };
commentAnnotation.attrs.conversation.push(obj);
dispatch(
tr.addMark(
commentAnnotation.pos,
commentAnnotation.pos + commentAnnotation.node.nodeSize,
commentMark.create({
...((commentAnnotation && commentAnnotation.attrs) || {}),
conversation: commentAnnotation.attrs.conversation
})
)
);
};
return (
......
......@@ -19,6 +19,7 @@ const Button = styled.button`
`;
const LinkComponent = ({ mark, setPosition, position }) => {
console.log(mark);
const href = mark ? mark.attrs.href : null,
linkMark = mark ? mark : null,
{ view: { main }, activeView } = useContext(WaxContext),
......
......@@ -156,6 +156,7 @@ const updateMarks = view => {
mark.type.name === "format_change"
) {
mark.pos = node.pos;
mark.node = node.node;
finalMarks.push(mark);
}
});
......
......@@ -15,7 +15,7 @@ const comment = {
class: hook.dom.getAttribute("class"),
id: hook.dom.dataset.id,
group: hook.dom.dataset.group,
conversation: hook.dom.dataset.conversation
conversation: JSON.parse(hook.dom.dataset.conversation)
});
next();
}
......
......@@ -62,10 +62,15 @@ const findChildrenByMark = (node, markType, descend) => {
return findChildren(node, child => markType.isInSet(child.marks), descend);
};
export const findChildrenByAttr = (node, predicate, descend) => {
return findChildren(node, child => !!predicate(child.attrs), descend);
};
export default {
findMark,
findBlockNodes,
findChildrenByType,
findInlineNodes,
findChildrenByMark
findChildrenByMark,
findChildrenByAttr
};
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