From ea56f39a53fee6e411f083cf73ab70d4d47e74e0 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Wed, 23 Sep 2020 22:53:46 -0400 Subject: [PATCH] Mithril 2 Update (#52) Update for Mithril 2 - Please note that PostQuoteButton and AutocompleteDropdown are not Fragments, not Components. Accordingly, they have been moved to the components folder. Co-authored-by: Matthew Kilgore Co-authored-by: Franz Liedke --- .../js/src/forum/addComposerAutocomplete.js | 13 +++-- .../js/src/forum/addMentionedByList.js | 13 ++--- .../js/src/forum/addPostMentionPreviews.js | 16 +++--- .../js/src/forum/addPostQuoteButton.js | 12 +++-- .../js/src/forum/addPostReplyAction.js | 10 ++-- .../components/PostMentionedNotification.js | 6 +-- .../src/forum/components/PostQuoteButton.js | 53 ------------------- .../components/UserMentionedNotification.js | 6 +-- .../AutocompleteDropdown.js | 17 +++--- .../js/src/forum/fragments/PostQuoteButton.js | 53 +++++++++++++++++++ extensions/mentions/js/src/forum/index.js | 5 +- 11 files changed, 101 insertions(+), 103 deletions(-) delete mode 100644 extensions/mentions/js/src/forum/components/PostQuoteButton.js rename extensions/mentions/js/src/forum/{components => fragments}/AutocompleteDropdown.js (84%) create mode 100644 extensions/mentions/js/src/forum/fragments/PostQuoteButton.js diff --git a/extensions/mentions/js/src/forum/addComposerAutocomplete.js b/extensions/mentions/js/src/forum/addComposerAutocomplete.js index adb634b6e..378f2cbed 100644 --- a/extensions/mentions/js/src/forum/addComposerAutocomplete.js +++ b/extensions/mentions/js/src/forum/addComposerAutocomplete.js @@ -11,14 +11,12 @@ import highlight from 'flarum/helpers/highlight'; import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable'; import { truncate } from 'flarum/utils/string'; -import AutocompleteDropdown from './components/AutocompleteDropdown'; +import AutocompleteDropdown from './fragments/AutocompleteDropdown'; export default function addComposerAutocomplete() { - extend(TextEditor.prototype, 'config', function(original, isInitialized) { - if (isInitialized) return; - + extend(TextEditor.prototype, 'oncreate', function () { const $container = $('
'); - const dropdown = new AutocompleteDropdown({items: []}); + const dropdown = new AutocompleteDropdown(); const $textarea = this.$('textarea').wrap('
'); const searched = []; let mentionStart; @@ -77,7 +75,8 @@ export default function addComposerAutocomplete() { const makeSuggestion = function(user, replacement, content, className = '') { const username = usernameHelper(user); if (typed) { - username.children[0] = highlight(username.children[0], typed); + username.children = [highlight(username.text, typed)]; + delete username.text; } return ( @@ -150,7 +149,7 @@ export default function addComposerAutocomplete() { } if (suggestions.length) { - dropdown.props.items = suggestions; + dropdown.items = suggestions; m.render($container[0], dropdown.render()); dropdown.show(); diff --git a/extensions/mentions/js/src/forum/addMentionedByList.js b/extensions/mentions/js/src/forum/addMentionedByList.js index ada296a3f..05cffe1dd 100644 --- a/extensions/mentions/js/src/forum/addMentionedByList.js +++ b/extensions/mentions/js/src/forum/addMentionedByList.js @@ -11,7 +11,7 @@ export default function addMentionedByList() { Post.prototype.mentionedBy = Model.hasMany('mentionedBy'); extend(CommentPost.prototype, 'footerItems', function(items) { - const post = this.props.post; + const post = this.attrs.post; const replies = post.mentionedBy(); if (replies && replies.length) { @@ -21,10 +21,8 @@ export default function addMentionedByList() { .one('transitionend', function() { $(this).hide(); }); }; - const config = function(element, isInitialized) { - if (isInitialized) return; - - const $this = $(element); + const oncreate = function(vnode) { + const $this = $(vnode.dom); let timeout; const $preview = $('