From 9db75678a9fb4d4a269ac89a4abc0a69a17a4f5d Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Thu, 14 Mar 2024 09:11:22 +0200 Subject: [PATCH] render comments on load --- editors/demo/src/Editoria/config/config.js | 9 +++++++-- .../src/CommentsService/CommentsService.js | 9 +++++++++ .../src/CommentsService/components/ConnectedComment.js | 3 +-- .../src/CommentsService/plugins/AnnotationPlugin.js | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/editors/demo/src/Editoria/config/config.js b/editors/demo/src/Editoria/config/config.js index 50a91f813..7a274eb97 100644 --- a/editors/demo/src/Editoria/config/config.js +++ b/editors/demo/src/Editoria/config/config.js @@ -61,13 +61,17 @@ async function DummyPromise(userInput) { } const updateTitle = debounce(title => { - console.log(title); + // console.log(title); }, 100); const getComments = debounce(comments => { - // console.log(comments); + console.log(comments); }, 2000); +const setComments = (comments = []) => { + return comments; +}; + const saveTags = tags => { // console.log(tags); }; @@ -167,6 +171,7 @@ export default { CommentsService: { showTitle: true, getComments, + setComments, }, CustomTagService: { diff --git a/wax-prosemirror-services/src/CommentsService/CommentsService.js b/wax-prosemirror-services/src/CommentsService/CommentsService.js index dedf6d5bf..f787157ce 100644 --- a/wax-prosemirror-services/src/CommentsService/CommentsService.js +++ b/wax-prosemirror-services/src/CommentsService/CommentsService.js @@ -24,6 +24,15 @@ export default class CommentsService extends Service { const options = { styles: {}, + existingComments: () => { + const map = new Map(); + if (commentsConfig.setComments().length > 0) { + commentsConfig.setComments().forEach(value => { + map.set(value.id, value); + }); + } + return map; + }, onSelectionChange: items => { this.allCommentsFromStates = this.allCommentsFromStates.filter( comm => diff --git a/wax-prosemirror-services/src/CommentsService/components/ConnectedComment.js b/wax-prosemirror-services/src/CommentsService/components/ConnectedComment.js index 92e95ca40..82175d043 100644 --- a/wax-prosemirror-services/src/CommentsService/components/ConnectedComment.js +++ b/wax-prosemirror-services/src/CommentsService/components/ConnectedComment.js @@ -2,9 +2,8 @@ /* eslint react/prop-types: 0 */ import React, { useContext, useMemo, useState, useEffect } from 'react'; import { TextSelection } from 'prosemirror-state'; -import { last, maxBy, minBy } from 'lodash'; import styled from 'styled-components'; -import { WaxContext, DocumentHelpers, Commands } from 'wax-prosemirror-core'; +import { WaxContext } from 'wax-prosemirror-core'; import { override } from '@pubsweet/ui-toolkit'; import CommentBox from './ui/comments/CommentBox'; import { AnnotationPluginKey } from '../plugins/AnnotationPlugin'; diff --git a/wax-prosemirror-services/src/CommentsService/plugins/AnnotationPlugin.js b/wax-prosemirror-services/src/CommentsService/plugins/AnnotationPlugin.js index f5212ec8b..27fdb670e 100644 --- a/wax-prosemirror-services/src/CommentsService/plugins/AnnotationPlugin.js +++ b/wax-prosemirror-services/src/CommentsService/plugins/AnnotationPlugin.js @@ -12,7 +12,7 @@ export const AnnotationPlugin = (name, options) => { init() { return new AnnotationState({ styles: options.styles, - map: new Map(), + map: options.existingComments(), instance: options.instance, onAnnotationListChange: options.onAnnotationListChange, onSelectionChange: options.onSelectionChange, -- GitLab