Skip to content

Commit

Permalink
Social: Default to the current post ID for share status (#39112)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk authored and gogdzl committed Oct 25, 2024
1 parent 68d7029 commit 83b13e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Social: Default to the current post ID for share status selector
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ export function getConnections() {
/**
* Resolves the post share status.
*
* @param {number} postId - The post ID.
* @param {number} _postId - The post ID.
*
* @return {Function} Resolver
*/
export function getPostShareStatus( postId ) {
return async ( { dispatch } ) => {
if ( ! postId ) {
return;
}
export function getPostShareStatus( _postId ) {
return async ( { dispatch, registry } ) => {
// Default to the current post ID if none is provided.
const postId = _postId || registry.select( editorStore ).getCurrentPostId();

try {
dispatch( fetchPostShareStatus( postId ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createRegistrySelector } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { PostShareStatus, SocialStoreState } from '../types';

/**
Expand All @@ -6,11 +8,17 @@ import { PostShareStatus, SocialStoreState } from '../types';
* @param {SocialStoreState} state - State object.
* @param {number} postId - The post ID.
*
* @return {SocialStoreState[number]} - The post share status.
* @return {PostShareStatus} - The post share status.
*/
export function getPostShareStatus( state: SocialStoreState, postId: number ): PostShareStatus {
return state.shareStatus?.[ postId ] ?? { shares: [] };
}
export const getPostShareStatus = createRegistrySelector(
select =>
( state: SocialStoreState, postId?: number ): PostShareStatus => {
// Default to the current post ID if none is provided.
const id = postId || select( editorStore ).getCurrentPostId();

return state.shareStatus?.[ id ] ?? { shares: [] };
}
);

/**
* Whether the share status modal is open.
Expand Down

0 comments on commit 83b13e5

Please sign in to comment.