From 4a3bb0d7465f0745d70db47a29e0c504affb579b Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Wed, 28 Aug 2024 18:43:52 +0530 Subject: [PATCH] Social: Hide share status when no connection is enabled --- ...fix-social-hide-share-status-when-no-connection-is-on | 4 ++++ .../src/components/post-publish-share-status/index.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 projects/js-packages/publicize-components/changelog/fix-social-hide-share-status-when-no-connection-is-on diff --git a/projects/js-packages/publicize-components/changelog/fix-social-hide-share-status-when-no-connection-is-on b/projects/js-packages/publicize-components/changelog/fix-social-hide-share-status-when-no-connection-is-on new file mode 100644 index 0000000000000..4bc68b5f4acd1 --- /dev/null +++ b/projects/js-packages/publicize-components/changelog/fix-social-hide-share-status-when-no-connection-is-on @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed share status being shown even if no connection is enabled diff --git a/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx b/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx index f6be5f78cf509..72a6565312f65 100644 --- a/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx +++ b/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx @@ -2,6 +2,7 @@ import { useSelect } from '@wordpress/data'; import { PluginPostPublishPanel } from '@wordpress/edit-post'; import { store as editorStore } from '@wordpress/editor'; import { usePostMeta } from '../../hooks/use-post-meta'; +import { usePostPrePublishValue } from '../../hooks/use-post-pre-publish-value'; import { store as socialStore } from '../../social-store'; import { ShareStatus } from './share-status'; @@ -11,7 +12,7 @@ import { ShareStatus } from './share-status'; * @return {import('react').ReactNode} - Post publish share status component. */ export function PostPublishShareStatus() { - const { isPublicizeEnabled: willPostBeShared } = usePostMeta(); + const { isPublicizeEnabled } = usePostMeta(); const { featureFlags, postId, isPostPublised } = useSelect( select => { const store = select( socialStore ); @@ -25,6 +26,12 @@ export function PostPublishShareStatus() { }; }, [] ); + const enabledConnections = usePostPrePublishValue( + useSelect( select => select( socialStore ).getEnabledConnections(), [] ) + ); + + const willPostBeShared = isPublicizeEnabled && enabledConnections.length > 0; + if ( ! featureFlags.useShareStatus || ! willPostBeShared || ! isPostPublised ) { return null; }