From efd0f15b56f25d06312ddc26dc3437e1046cd291 Mon Sep 17 00:00:00 2001 From: Gergely Juhasz Date: Thu, 29 Aug 2024 12:51:10 +0200 Subject: [PATCH 1/3] Only show modal trigger if there are shares for the post --- .../components/share-status/modal-trigger.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx b/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx index df1a3373f21f9..945478e951f84 100644 --- a/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx +++ b/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx @@ -1,5 +1,6 @@ import { Button } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; +import { store as editorStore } from '@wordpress/editor'; import { __ } from '@wordpress/i18n'; import { forwardRef } from 'react'; import { store as socialStore } from '../../social-store'; @@ -16,8 +17,21 @@ type ModalTriggerProps = ButtonProps & { export const ModalTrigger = forwardRef( ( { withWrapper = false, ...props }: ModalTriggerProps, ref: unknown ) => { const { openShareStatusModal } = useDispatch( socialStore ); - const featureFlags = useSelect( select => select( socialStore ).featureFlags(), [] ); + const { shareStatus } = useSelect( select => { + const store = select( socialStore ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript + const _editorStore = select( editorStore ) as any; + + return { + shareStatus: store.getPostShareStatus( _editorStore.getCurrentPostId() ), + }; + }, [] ); + + // If the post is not shared anywhere, thus there is no share status or no shares, we don't need to show the trigger. + if ( ! shareStatus || ! shareStatus.shares || shareStatus.shares.length === 0 ) { + return null; + } if ( ! featureFlags.useShareStatus ) { return null; From 2aae9ac31b2aa0314577f719a1cbde745ee33a96 Mon Sep 17 00:00:00 2001 From: Gergely Juhasz Date: Thu, 29 Aug 2024 12:51:43 +0200 Subject: [PATCH 2/3] changelog --- .../changelog/fix-social-share-modal-trigger-presence | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/js-packages/publicize-components/changelog/fix-social-share-modal-trigger-presence diff --git a/projects/js-packages/publicize-components/changelog/fix-social-share-modal-trigger-presence b/projects/js-packages/publicize-components/changelog/fix-social-share-modal-trigger-presence new file mode 100644 index 0000000000000..37daf9ef5067e --- /dev/null +++ b/projects/js-packages/publicize-components/changelog/fix-social-share-modal-trigger-presence @@ -0,0 +1,4 @@ +Significance: minor +Type: fixed + +Fixed a bug on when to show the share log modal trigger From 42eb3c5aacdbde76980e51578df3cd1f665a9684 Mon Sep 17 00:00:00 2001 From: Gergely Juhasz Date: Thu, 29 Aug 2024 13:12:38 +0200 Subject: [PATCH 3/3] Use only socialStore --- .../src/components/share-status/modal-trigger.tsx | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx b/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx index 945478e951f84..88521d45c5c65 100644 --- a/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx +++ b/projects/js-packages/publicize-components/src/components/share-status/modal-trigger.tsx @@ -1,6 +1,5 @@ import { Button } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; -import { store as editorStore } from '@wordpress/editor'; import { __ } from '@wordpress/i18n'; import { forwardRef } from 'react'; import { store as socialStore } from '../../social-store'; @@ -18,15 +17,7 @@ export const ModalTrigger = forwardRef( ( { withWrapper = false, ...props }: ModalTriggerProps, ref: unknown ) => { const { openShareStatusModal } = useDispatch( socialStore ); const featureFlags = useSelect( select => select( socialStore ).featureFlags(), [] ); - const { shareStatus } = useSelect( select => { - const store = select( socialStore ); - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript - const _editorStore = select( editorStore ) as any; - - return { - shareStatus: store.getPostShareStatus( _editorStore.getCurrentPostId() ), - }; - }, [] ); + const shareStatus = useSelect( select => select( socialStore ).getPostShareStatus(), [] ); // If the post is not shared anywhere, thus there is no share status or no shares, we don't need to show the trigger. if ( ! shareStatus || ! shareStatus.shares || shareStatus.shares.length === 0 ) {