From 76729e8d4881db30312c3cefe4f36f96092256f7 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 5 May 2020 18:04:15 +0300 Subject: [PATCH] active comment for notes --- .../src/components/comments/CommentBox.js | 4 ++-- .../src/components/comments/CommentComponent.js | 6 ++++-- .../src/components/notes/NoteEditorContainer.js | 4 ++++ wax-prosemirror-services/src/NoteService/Editor.js | 3 +-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wax-prosemirror-components/src/components/comments/CommentBox.js b/wax-prosemirror-components/src/components/comments/CommentBox.js index f790aa2f1..301591f51 100644 --- a/wax-prosemirror-components/src/components/comments/CommentBox.js +++ b/wax-prosemirror-components/src/components/comments/CommentBox.js @@ -30,9 +30,9 @@ const CommentBoxStyled = styled.div` export default ({ mark, view, top, dataComment }) => { const [animate, setAnimate] = useState(false); - const { view: { main }, app } = useContext(WaxContext); + const { view: { main }, app, activeView } = useContext(WaxContext); const activeCommentPlugin = app.PmPlugins.get("activeComment"); - const activeComment = activeCommentPlugin.getState(main.state).comment; + const activeComment = activeCommentPlugin.getState(activeView.state).comment; let active = false; if (activeComment && mark.attrs.id === activeComment.attrs.id) active = true; useEffect(() => { diff --git a/wax-prosemirror-components/src/components/comments/CommentComponent.js b/wax-prosemirror-components/src/components/comments/CommentComponent.js index 8152e2237..6746b4dc7 100644 --- a/wax-prosemirror-components/src/components/comments/CommentComponent.js +++ b/wax-prosemirror-components/src/components/comments/CommentComponent.js @@ -13,7 +13,7 @@ import CommentsBoxList from "./CommentsBoxList"; import { each } from "lodash"; export default ({ area }) => { - const { view: { main }, app } = useContext(WaxContext); + const { view: { main }, app, activeView } = useContext(WaxContext); const activeCommentPlugin = app.PmPlugins.get("activeComment"); const [comments, setComments] = useState([]); const [position, setPosition] = useState(); @@ -30,7 +30,9 @@ export default ({ area }) => { each(comments[area], (comment, pos) => { const WaxSurface = main.dom.getBoundingClientRect(); const { attrs: { id } } = comment; - const activeComment = activeCommentPlugin.getState(main.state).comment; + const activeComment = activeCommentPlugin.getState(activeView.state) + .comment; + let isActive = false; if (activeComment && comment.attrs.id === activeComment.attrs.id) isActive = true; diff --git a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js index a978fa279..9acb8015c 100644 --- a/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js +++ b/wax-prosemirror-components/src/components/notes/NoteEditorContainer.js @@ -26,6 +26,10 @@ const NoteStyled = styled.div` span.comment { border-bottom: 2px solid #ffab20; border-radius: 3px 3px 0 0; + + .active-comment { + background-color: #ffab20; + } } `; diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index 864917027..f10e5ea53 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -15,14 +15,13 @@ export default ({ node, view }) => { const editorRef = useRef(); const context = useContext(WaxContext); const noteId = node.attrs.id; - useEffect(() => { const noteView = new EditorView( { mount: editorRef.current }, { state: EditorState.create({ doc: node, - plugins: [keymap(createKeyBindings())] + plugins: [keymap(createKeyBindings()), ...context.app.getPlugins()] }), // This is the magic part dispatchTransaction: tr => { -- GitLab