Skip to content

Commit

Permalink
Only show modal trigger if there are shares for the post
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Aug 29, 2024
1 parent 48ac019 commit efd0f15
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit efd0f15

Please sign in to comment.