From b402e0049fef5260c2cdec783aad9553a67ef7da Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 22 Feb 2017 11:43:03 +0200 Subject: [PATCH] Handle Document Change to update live / TOC / Commnets/ Notes --- .../SimpleEditor/panes/Comments/CommentBoxList.js | 10 ++++++++-- app/components/SimpleEditor/panes/Notes/Notes.js | 7 ++++--- .../panes/TableOfContents/TableOfContents.js | 14 +++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js index 61736af..164b313 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 398674c..e153b8d 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 6cd695e..fd109a1 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 ($$) { -- GitLab