diff --git a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js index 61736afdcebdbee1b412bce7b2ab943a7dfd5324..164b313c03462649bb2eca7f70a0c2d62d6e7af8 100644 --- a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js +++ b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js @@ -14,6 +14,7 @@ class CommentBoxList extends Component { didMount () { const provider = this.getProvider() provider.on('comments:updated', this.onCommentsUpdated, this) + this.context.editorSession.onUpdate('document', this.getCommentEntries, this) this.setTops() } @@ -22,11 +23,16 @@ class CommentBoxList extends Component { this.setTops() } + getCommentEntries (change) { + const provider = this.getProvider() + provider.handleDocumentChange(change) + this.rerender() + } + render ($$) { const self = this const provider = self.getProvider() - // const entries = provider.getEntries() - const entries = provider.computeEntries() + const entries = provider.getEntries() const activeEntry = provider.activeEntry const { comments, user } = self.props diff --git a/app/components/SimpleEditor/panes/Notes/Notes.js b/app/components/SimpleEditor/panes/Notes/Notes.js index 398674c4eb5ebdfc31755fa2f145e0253aac366f..e153b8d8e86b32f4094b317b1971b02027a28cd7 100644 --- a/app/components/SimpleEditor/panes/Notes/Notes.js +++ b/app/components/SimpleEditor/panes/Notes/Notes.js @@ -3,8 +3,7 @@ import { Component } from 'substance' class Notes extends Component { // use toc:updated to avoid rewriting TOCProvider's this.handleDocumentChange didMount () { - const provider = this.getProvider() - provider.on('toc:updated', this.onNotesUpdated, this) + this.context.editorSession.onUpdate('document', this.onNotesUpdated, this) } render ($$) { @@ -29,7 +28,9 @@ class Notes extends Component { return this.context.notesProvider } - onNotesUpdated () { + onNotesUpdated (change) { + const notesProvider = this.getProvider() + notesProvider.handleDocumentChange(change) this.rerender() } diff --git a/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js b/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js index 6cd695edcf292b4fbc5a784a94425444421c5c90..fd109a1ff7f2bf7dcd9719a20149a9647a264c48 100644 --- a/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js +++ b/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js @@ -12,7 +12,19 @@ class TableOfContents extends Toc { this.rerender() }) - // this.on('toc:updated', this.reComputeEntries, this) + } + + // TODO better way? after editor's initial render ,every change in the document is not + // updated. Editor never emits the event "document:updated". Workourand for now On didMound execute + // handleDocumentChange to decide if there is a change to be reflected in the TOC + didMount () { + this.context.editorSession.onUpdate('document', this.getTocEntries, this) + } + + getTocEntries (change) { + const tocProvider = this.getProvider() + tocProvider.handleDocumentChange(change) + this.rerender() } render ($$) {