Skip to content

Commit

Permalink
Reload settings page if publicize is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed May 3, 2024
1 parent d01a0bc commit 66b0aa6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export type SocialStoreState = {

declare global {
interface Window {
jetpackSocialInitialState?: SocialStoreState;
jetpackSocialInitialState?: SocialStoreState & {
is_publicize_enabled: boolean;
};
}
}
8 changes: 8 additions & 0 deletions projects/plugins/jetpack/_inc/client/sharing/publicize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export const Publicize = withModuleSettingsFormHelpers(
} );
}

componentDidUpdate() {
const isActive = this.props.getOptionValue( 'publicize' );
// Reload the page if Publicize is enabled.
if ( isActive && ! window.Initial_State.socialInitialState.is_publicize_enabled ) {
window.location.reload();
}
}

render() {
const unavailableInOfflineMode = this.props.isUnavailableInOfflineMode( 'publicize' ),
isLinked = this.props.isLinked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const SocialModuleToggle: React.FC = () => {

const updateOptions = useDispatch( SOCIAL_STORE_ID ).updateJetpackSettings;

const toggleModule = useCallback( () => {
const toggleModule = useCallback( async () => {
const newOption = {
publicize_active: ! isModuleEnabled,
};
updateOptions( newOption );
await updateOptions( newOption );

// If the module was enabled, we need to refresh the connection list
if ( newOption.publicize_active && ! window.jetpackSocialInitialState.is_publicize_enabled ) {
window.location.reload();
}
}, [ isModuleEnabled, updateOptions ] );

const [ isSmall ] = useBreakpointMatch( 'sm' );
Expand Down

0 comments on commit 66b0aa6

Please sign in to comment.