X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/5c92b72fdd419ccb6f77bfdf0a1cb1358c51a9d8..refs/pull/5295/head:/resources/js/components/page-comments.js diff --git a/resources/js/components/page-comments.js b/resources/js/components/page-comments.js index ebcc95f07..1d6abfe20 100644 --- a/resources/js/components/page-comments.js +++ b/resources/js/components/page-comments.js @@ -1,6 +1,6 @@ import {Component} from './component'; import {getLoading, htmlToDom} from '../services/dom'; -import {buildForInput} from "../wysiwyg/config"; +import {buildForInput} from '../wysiwyg-tinymce/config'; export class PageComments extends Component { @@ -40,7 +40,7 @@ export class PageComments extends Component { setupListeners() { this.elem.addEventListener('page-comment-delete', () => { - this.updateCount(); + setTimeout(() => this.updateCount(), 1); this.hideForm(); }); @@ -65,15 +65,20 @@ export class PageComments extends Component { this.form.after(loading); this.form.toggleAttribute('hidden', true); - const text = this.formInput.value; const reqData = { - text, + html: this.wysiwygEditor.getContent(), parent_id: this.parentId || null, }; window.$http.post(`/comment/${this.pageId}`, reqData).then(resp => { const newElem = htmlToDom(resp.data); - this.formContainer.after(newElem); + + if (reqData.parent_id) { + this.formContainer.after(newElem); + } else { + this.container.append(newElem); + } + window.$events.success(this.createdText); this.hideForm(); this.updateCount(); @@ -88,10 +93,12 @@ export class PageComments extends Component { updateCount() { const count = this.getCommentCount(); - this.commentsTitle.textContent = window.trans_plural(this.countText, count, {count}); + console.log('update count', count, this.container); + this.commentsTitle.textContent = window.$trans.choice(this.countText, count, {count}); } resetForm() { + this.removeEditor(); this.formInput.value = ''; this.parentId = null; this.replyToRow.toggleAttribute('hidden', true); @@ -99,6 +106,7 @@ export class PageComments extends Component { } showForm() { + this.removeEditor(); this.formContainer.toggleAttribute('hidden', false); this.addButtonContainer.toggleAttribute('hidden', true); this.formContainer.scrollIntoView({behavior: 'smooth', block: 'nearest'}); @@ -118,6 +126,7 @@ export class PageComments extends Component { loadEditor() { if (this.wysiwygEditor) { + this.wysiwygEditor.focus(); return; } @@ -132,10 +141,17 @@ export class PageComments extends Component { window.tinymce.init(config).then(editors => { this.wysiwygEditor = editors[0]; - this.wysiwygEditor.focus(); + setTimeout(() => this.wysiwygEditor.focus(), 50); }); } + removeEditor() { + if (this.wysiwygEditor) { + this.wysiwygEditor.remove(); + this.wysiwygEditor = null; + } + } + getCommentCount() { return this.container.querySelectorAll('[component="page-comment"]').length; }