From a2779ab8eee9f332a93cfe8927b8c83d6aae92f1 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Sun, 19 Feb 2017 15:22:38 +0200
Subject: [PATCH] fixes: you can add comment and update active entry

---
 app/components/SimpleEditor/Editor.js            |  2 +-
 .../SimpleEditor/panes/Comments/CommentBox.js    | 10 ++++------
 .../panes/Comments/CommentBoxList.js             |  6 ++++--
 .../panes/Comments/CommentsProvider.js           | 16 ++++++++--------
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/app/components/SimpleEditor/Editor.js b/app/components/SimpleEditor/Editor.js
index a927983..39e440b 100644
--- a/app/components/SimpleEditor/Editor.js
+++ b/app/components/SimpleEditor/Editor.js
@@ -44,7 +44,7 @@ class Editor extends ProseEditor {
 
   didMount () {
     console.log(this.editorSession)
-    this.editorSession.onUpdate('document', this.rerender, this, {})
+    // this.editorSession.onUpdate('document', this.rerender, this, {})
     // this.documentSession.on('didUpdate', this.documentSessionUpdated, this)
     // this.documentSession.on('fileUploadTrigger', this.handleUpload, this)
     this.extendState({ editorReady: true })
diff --git a/app/components/SimpleEditor/panes/Comments/CommentBox.js b/app/components/SimpleEditor/panes/Comments/CommentBox.js
index 3728ab0..89fe6f3 100644
--- a/app/components/SimpleEditor/panes/Comments/CommentBox.js
+++ b/app/components/SimpleEditor/panes/Comments/CommentBox.js
@@ -8,16 +8,14 @@ import {
 import CommentList from './CommentList'
 
 class CommentBox extends Component {
-  constructor (props) {
-    super(props)
+  constructor (props, args) {
+    super(props, args)
     this.inputHeight = 0
   }
 
   // TODO -- fix class names
   render ($$) {
-    console.log('in comment box')
-    const active = this.props.active
-    const entry = this.props.entry
+    const {active, entry} = this.props
 
     let comments = this.props.comments.data
 
@@ -85,7 +83,7 @@ class CommentBox extends Component {
   textAreaAdjust (event) {
     const value = this.refs.commentReply.getValue()
     let replyBtn = this.refs.commentReplyButton
-
+    console.log('replyBn', replyBtn)
     if (value.trim().length > 0) {
       replyBtn.removeAttr('disabled')
     } else {
diff --git a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js
index 49a9dce..e7aacbe 100644
--- a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js
+++ b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js
@@ -28,15 +28,16 @@ class CommentBoxList extends Component {
     // const entries = provider.getEntries()
     const entries = provider.computeEntries()
     const activeEntry = provider.activeEntry
+    const { comments, user } = self.props
 
     const listItems = entries.map(function (entry, i) {
       const active = (entry.id === activeEntry)
       return $$(CommentBox, {
         active: active,
-        comments: self.props.comments[entry.id] || { data: [] },
+        comments: comments[entry.id] || { data: [] },
         entry: entry,
         parent: self,
-        user: self.props.user
+        user: user
       })
     })
 
@@ -115,6 +116,7 @@ class CommentBoxList extends Component {
 
       // if active, move as many boxes above as needed to bring it to the annotation's height
       if (isActive) {
+        console.log('isActive', isActive)
         entry.endHeight = annotationTop + boxHeight + 2
         result[pos] = annotationTop
 
diff --git a/app/components/SimpleEditor/panes/Comments/CommentsProvider.js b/app/components/SimpleEditor/panes/Comments/CommentsProvider.js
index 10c5be7..dc05372 100644
--- a/app/components/SimpleEditor/panes/Comments/CommentsProvider.js
+++ b/app/components/SimpleEditor/panes/Comments/CommentsProvider.js
@@ -7,7 +7,7 @@ class CommentsProvider extends TocProvider {
     super(document, props)
     this.activeEntry = null
     const editorSession = props.editorSession
-    editorSession.onUpdate('document', this.updateActiveEntry, this)
+    editorSession.onUpdate('', this.updateActiveEntry, this)
 
     const doc = editorSession.getDocument()
     doc.on('document:changed', this.update, this)
@@ -252,11 +252,11 @@ class CommentsProvider extends TocProvider {
     const comments = this.getSelectionComments()
     if (comments.length === 0) return
 
-    const minComment = _.minBy(comments, 'startOffset')
-    const maxComment = _.maxBy(comments, 'endOffset')
+    const minComment = _.minBy(comments, 'start.offset')
+    const maxComment = _.maxBy(comments, 'end.offset')
 
-    const min = minComment.startOffset
-    const max = maxComment.endOffset
+    const min = minComment.start.offset
+    const max = maxComment.end.offset
 
     return {
       start: min,
@@ -281,8 +281,8 @@ class CommentsProvider extends TocProvider {
     const selection = this.getSelection()
 
     if (
-      selection.startOffset < commentBorders.start ||
-      selection.endOffset > commentBorders.end
+      selection.start.offset < commentBorders.start ||
+      selection.end.offset > commentBorders.end
     ) return true
 
     return false
@@ -376,7 +376,7 @@ class CommentsProvider extends TocProvider {
     comments = _.map(comments, function (comment) {
       const blockId = comment.path[0]
       const blockPosition = container.getPosition(blockId)
-      const nodePosition = comment.startOffset
+      const nodePosition = comment.start.offset
 
       return {
         id: comment.id,
-- 
GitLab