diff --git a/ghost/admin/app/components/modal-post-share.hbs b/ghost/admin/app/components/modal-post-share.hbs new file mode 100644 index 0000000000..c71b074d87 --- /dev/null +++ b/ghost/admin/app/components/modal-post-share.hbs @@ -0,0 +1,59 @@ + diff --git a/ghost/admin/app/components/modal-post-share.js b/ghost/admin/app/components/modal-post-share.js new file mode 100644 index 0000000000..dec29a979c --- /dev/null +++ b/ghost/admin/app/components/modal-post-share.js @@ -0,0 +1,95 @@ +import Component from '@glimmer/component'; +import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard'; +import {action} from '@ember/object'; +import {capitalize} from '@ember/string'; +import {inject as service} from '@ember/service'; +import {task, timeout} from 'ember-concurrency'; + +export default class PostShareModal extends Component { + @service store; + @service router; + @service notifications; + + static modalOptions = { + className: 'fullscreen-modal-wide fullscreen-modal-action modal-post-success' + }; + + get post() { + return this.args.data.post; + } + + get postCount() { + return this.args.data.postCount; + } + + get showPostCount() { + return this.args.data.showPostCount; + } + + @action + handleTwitter() { + window.open(`https://twitter.com/intent/tweet?url=${encodeURI(this.post.url)}`, '_blank'); + } + + @action + handleThreads() { + window.open(`https://threads.net/intent/post?text=${encodeURI(this.post.url)}`, '_blank'); + } + + @action + handleFacebook() { + window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURI(this.post.url)}`, '_blank'); + } + + @action + handleLinkedIn() { + window.open(`http://www.linkedin.com/shareArticle?mini=true&url=${encodeURI(this.post.url)}`, '_blank'); + } + + @action + viewInBrowser() { + window.open(this.post.url, '_blank'); + } + + @task + *handleCopyLink() { + copyTextToClipboard(this.post.url); + yield timeout(1000); + return true; + } + + @task + *handleCopyPreviewLink() { + copyTextToClipboard(this.post.previewUrl); + yield timeout(1000); + return true; + } + + @task + *revertToDraftTask() { + const currentPost = this.post; + const originalStatus = currentPost.status; + const originalPublishedAtUTC = currentPost.publishedAtUTC; + + try { + if (currentPost.isScheduled) { + currentPost.publishedAtUTC = null; + } + + currentPost.status = 'draft'; + currentPost.emailOnly = false; + + yield currentPost.save(); + this.router.transitionTo('lexical-editor.edit', 'post', currentPost.id); + + const postType = capitalize(currentPost.displayName); + this.notifications.showNotification(`${postType} reverted to a draft.`, {type: 'success'}); + + return true; + } catch (e) { + currentPost.status = originalStatus; + currentPost.publishedAtUTC = originalPublishedAtUTC; + throw e; + } + } +} diff --git a/ghost/admin/app/components/posts/analytics.hbs b/ghost/admin/app/components/posts/analytics.hbs index e9f3a5a5b9..0d48449f48 100644 --- a/ghost/admin/app/components/posts/analytics.hbs +++ b/ghost/admin/app/components/posts/analytics.hbs @@ -42,7 +42,7 @@ {{/if}} {{#unless this.post.emailOnly}} - {{/unless}} diff --git a/ghost/admin/app/components/posts/analytics.js b/ghost/admin/app/components/posts/analytics.js index bbd035091e..3753b77878 100644 --- a/ghost/admin/app/components/posts/analytics.js +++ b/ghost/admin/app/components/posts/analytics.js @@ -1,6 +1,7 @@ import Component from '@glimmer/component'; import DeletePostModal from '../modals/delete-post'; -import PostSuccessModal from '../modal-post-success'; +import PostShareModal from '../modal-post-share'; +import PostSuccessModal from '../modal-post-success'; import {action} from '@ember/object'; import {didCancel, task} from 'ember-concurrency'; import {inject as service} from '@ember/service'; @@ -65,6 +66,23 @@ export default class Analytics extends Component { } } + openShareModal() { + this.modals.open(PostShareModal, { + post: this.post, + postCount: this.postCount, + showPostCount: this.showPostCount + }); + } + + async checkShareModal() { + if (localStorage.getItem('ghost-last-published-post')) { + await this.fetchPostCountTask.perform(); + this.showPostCount = true; + this.openShareModal(); + localStorage.removeItem('ghost-last-published-post'); + } + } + get post() { if (this.feature.publishFlowEndScreen) { return this._post ?? this.args.post; @@ -188,6 +206,12 @@ export default class Analytics extends Component { this.openPublishFlowModal(); } + @action + toggleShareModal() { + this.showPostCount = false; + this.openShareModal(); + } + @action confirmDeleteMember() { this.modals.open(DeletePostModal, {