Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social: Default to the current post ID for share status #39112

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading