-
Notifications
You must be signed in to change notification settings - Fork 801
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: Refresh store on Publicize module toggle via 1 call #34142
Changes from 6 commits
07cf749
61facfa
1902f5d
b441f37
3e98588
fa0dac4
4b5f559
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useDispatch } from '@wordpress/data'; | ||
import { SOCIAL_STORE_ID } from '../../social-store'; | ||
|
||
/** | ||
* HOC that refreshes all of the Jetpack Social settings in the store, to be used in class components. | ||
* | ||
* @param {object} props - The component props. | ||
* @param {boolean} props.shouldRefresh - Whether or not to refresh the settings. | ||
* @param {object} props.children - The children to render. | ||
* @returns { object } The refreshJetpackSocialSettings function. | ||
*/ | ||
export default function RefreshJetpackSocialSettingsWrapper( { shouldRefresh, children } ) { | ||
const refreshOptions = useDispatch( SOCIAL_STORE_ID ).refreshJetpackSocialSettings; | ||
|
||
if ( shouldRefresh ) { | ||
refreshOptions(); | ||
} | ||
|
||
return children; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { getRedirectUrl } from '@automattic/jetpack-components'; | ||
import { RefreshJetpackSocialSettingsWrapper } from '@automattic/jetpack-publicize-components'; | ||
import { createInterpolateElement } from '@wordpress/element'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import Card from 'components/card'; | ||
|
@@ -154,10 +155,14 @@ export const Publicize = withModuleSettingsFormHelpers( | |
> | ||
{ __( 'Automatically share your posts to social networks', 'jetpack' ) } | ||
</ModuleToggle> | ||
{ shouldShowChildElements && hasAutoConversion && <AutoConversionSection /> } | ||
{ shouldShowChildElements && hasSocialImageGenerator && ( | ||
<SocialImageGeneratorSection /> | ||
) } | ||
<RefreshJetpackSocialSettingsWrapper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using this component here so we can encapsulate the That's probably fine, but it might be worth checking that we don't want to do something like handle it with a lifecycle method in here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, and also |
||
shouldRefresh={ ! isActive && this.props.isSavingAnyOption( 'publicize' ) } | ||
> | ||
{ shouldShowChildElements && hasAutoConversion && <AutoConversionSection /> } | ||
{ shouldShowChildElements && hasSocialImageGenerator && ( | ||
<SocialImageGeneratorSection /> | ||
) } | ||
</RefreshJetpackSocialSettingsWrapper> | ||
</SettingsGroup> | ||
) } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this file should be in a folder named
refresh-social-settings