From ae1d2d957f21d8c959e0aa904348f7251e3748bd Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Mon, 21 Feb 2022 22:14:28 +0200 Subject: [PATCH] FEATURE: Replace share post popup with share modal (#15875) This uniformizes the topic share modal and the post link popup. It also introduces a new feature which can notify the user of a post. --- .../discourse/app/controllers/share-topic.js | 27 ++++++++++++++----- .../app/initializers/topic-footer-buttons.js | 2 +- .../app/templates/modal/share-topic.hbs | 8 +++--- .../discourse/app/templates/topic.hbs | 1 - .../discourse/app/widgets/post-menu.js | 6 +---- .../javascripts/discourse/app/widgets/post.js | 11 ++++++++ .../tests/integration/widgets/post-test.js | 5 +--- app/controllers/topics_controller.rb | 13 +++++++-- app/models/topic.rb | 4 +-- config/locales/client.en.yml | 6 ++++- spec/requests/topics_controller_spec.rb | 4 +++ 11 files changed, 62 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/share-topic.js b/app/assets/javascripts/discourse/app/controllers/share-topic.js index b9a06513730..638a704c319 100644 --- a/app/assets/javascripts/discourse/app/controllers/share-topic.js +++ b/app/assets/javascripts/discourse/app/controllers/share-topic.js @@ -16,19 +16,31 @@ export default Controller.extend( bufferedProperty("invite"), { topic: null, + post: null, + allowInvites: false, + showNotifyUsers: false, restrictedGroups: null, onShow() { - this.set("showNotifyUsers", false); + this.setProperties({ + topic: null, + post: null, + allowInvites: false, + showNotifyUsers: false, + }); if (this.model && this.model.read_restricted) { this.restrictedGroupWarning(); } }, - @discourseComputed("topic.shareUrl") - topicUrl(url) { - return url ? getAbsoluteURL(url) : null; + @discourseComputed("post.shareUrl", "topic.shareUrl") + url(postUrl, topicUrl) { + if (postUrl) { + return getAbsoluteURL(postUrl); + } else if (topicUrl) { + return getAbsoluteURL(topicUrl); + } }, @discourseComputed( @@ -57,7 +69,7 @@ export default Controller.extend( this.set("showNotifyUsers", false); Sharing.shareSource(source, { title: this.topic.title, - url: this.topicUrl, + url: this.url, }); }, @@ -81,7 +93,10 @@ export default Controller.extend( ajax(`/t/${this.topic.id}/invite-notify`, { type: "POST", - data: { usernames: this.users }, + data: { + usernames: this.users, + post_number: this.post ? this.post.post_number : undefined, + }, }) .then(() => { this.setProperties({ showNotifyUsers: false }); diff --git a/app/assets/javascripts/discourse/app/initializers/topic-footer-buttons.js b/app/assets/javascripts/discourse/app/initializers/topic-footer-buttons.js index a5a52277718..e00c100309f 100644 --- a/app/assets/javascripts/discourse/app/initializers/topic-footer-buttons.js +++ b/app/assets/javascripts/discourse/app/initializers/topic-footer-buttons.js @@ -18,7 +18,7 @@ export default { priority: SHARE_PRIORITY, label() { if (!this.get("topic.isPrivateMessage") || this.site.mobileView) { - return "topic.share.title"; + return "footer_nav.share"; } }, title: "topic.share.help", diff --git a/app/assets/javascripts/discourse/app/templates/modal/share-topic.hbs b/app/assets/javascripts/discourse/app/templates/modal/share-topic.hbs index 330637850b8..8c4c3a7a857 100644 --- a/app/assets/javascripts/discourse/app/templates/modal/share-topic.hbs +++ b/app/assets/javascripts/discourse/app/templates/modal/share-topic.hbs @@ -1,12 +1,14 @@ -{{#d-modal-body title="topic.share.title"}} +{{#d-modal-body rawTitle=(if post (i18n "post.share.title" post_number=post.post_number) (i18n "topic.share.title"))}}