From cc1f9e7be6f50eeaf6a0483ba542b25e608c84f6 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Wed, 20 Feb 2019 16:27:59 -0500 Subject: [PATCH] Fix share button in post menu --- .../javascripts/discourse/widgets/post.js.es6 | 32 +++++++++++++++++++ test/javascripts/acceptance/topic-test.js.es6 | 8 +++++ 2 files changed, 40 insertions(+) diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 0ec09d86b0e..a8a51610e7d 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -441,6 +441,38 @@ createWidget("post-contents", { return result; }, + _date(attrs) { + const lastWikiEdit = + attrs.wiki && attrs.lastWikiEdit && new Date(attrs.lastWikiEdit); + const createdAt = new Date(attrs.created_at); + return lastWikiEdit ? lastWikiEdit : createdAt; + }, + + share() { + const post = this.findAncestorModel(); + + const modalFallback = () => { + showModal("share-and-invite", { + modalClass: "share-and-invite", + panels: [ + { + id: "share", + title: "topic.share.extended_title", + model: { + postNumber: this.attrs.post_number, + shareUrl: this.attrs.shareUrl, + date: this._date(this.attrs), + postId: post.get("id"), + topic: post.get("topic") + } + } + ] + }); + }; + + nativeShare({ url: this.attrs.shareUrl }).then(null, modalFallback); + }, + toggleRepliesBelow(goToPost = "false") { if (this.state.repliesBelow.length) { this.state.repliesBelow = []; diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6 index b63b5d12704..fa50bef8b02 100644 --- a/test/javascripts/acceptance/topic-test.js.es6 +++ b/test/javascripts/acceptance/topic-test.js.es6 @@ -22,6 +22,14 @@ acceptance("Topic", { } }); + +QUnit.test("Share Modal", async assert => { + await visit("/t/internationalization-localization/280"); + + await click(".topic-post:first-child button.share"); + assert.ok(exists(".modal.share-and-invite"), "it shows the share and invite modal"); +}); + QUnit.test("Showing and hiding the edit controls", async assert => { await visit("/t/internationalization-localization/280");