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: Fix connection refresh logic #38350

Merged
merged 4 commits into from
Jul 17, 2024
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: fixed

Fixed double request issue and simplifed refresh logic
1 change: 0 additions & 1 deletion projects/js-packages/publicize-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import './src/social-store';

export { default as Connection } from './src/components/connection';
export { default as ConnectionVerify } from './src/components/connection-verify';
export { default as Form } from './src/components/form';
export { default as SocialPreviewsModal } from './src/components/social-previews/modal';
export { default as SocialPreviewsPanel } from './src/components/social-previews/panel';
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize-components",
"version": "0.56.1",
"version": "0.56.2-alpha",
"description": "A library of JS components required by the Publicize editor plugin",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/publicize-components/#readme",
"bugs": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import useImageGeneratorConfig from '../../hooks/use-image-generator-config';
import useMediaDetails from '../../hooks/use-media-details';
import useMediaRestrictions, { NO_MEDIA_ERROR } from '../../hooks/use-media-restrictions';
import useRefreshAutoConversionSettings from '../../hooks/use-refresh-auto-conversion-settings';
import useRefreshConnections from '../../hooks/use-refresh-connections';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import { store as socialStore } from '../../social-store';
import { ThemedConnectionsModal as ManageConnectionsModal } from '../manage-connections-modal';
Expand All @@ -41,7 +40,6 @@ import { ValidationNotice } from './validation-notice';
*/
export default function PublicizeForm() {
const { connections, hasConnections, hasEnabledConnections } = useSocialMediaConnections();
const refreshConnections = useRefreshConnections();
const { isEnabled: isSocialImageGeneratorEnabledForPost } = useImageGeneratorConfig();
const { shouldShowNotice, NOTICES } = useDismissNotice();
const {
Expand Down Expand Up @@ -94,8 +92,6 @@ export default function PublicizeForm() {
refreshAutoConversionSettings();
}

refreshConnections();

return (
<Wrapper>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { store as editorStore } from '@wordpress/editor';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import usePublicizeConfig from '../../hooks/use-publicize-config';
import useRefreshConnections from '../../hooks/use-refresh-connections';
import { usePostJustPublished } from '../../hooks/use-saving-post';
import useSelectSocialMediaConnections from '../../hooks/use-social-media-connections';
import PublicizeConnectionVerify from '../connection-verify';
import PublicizeForm from '../form';
import { ManualSharing } from '../manual-sharing';
import { SharePostRow } from '../share-post';
Expand All @@ -21,6 +21,7 @@ import './global.scss';
const PublicizePanel = ( { prePublish, children } ) => {
const { refresh, hasConnections, hasEnabledConnections } = useSelectSocialMediaConnections();
const isPostPublished = useSelect( select => select( editorStore ).isCurrentPostPublished(), [] );
const refreshConnections = useRefreshConnections();

const { isPublicizeEnabled, hidePublicizeFeature, togglePublicizeFeature } = usePublicizeConfig();

Expand All @@ -42,6 +43,8 @@ const PublicizePanel = ( { prePublish, children } ) => {
? {}
: { title: __( 'Share this post', 'jetpack' ), className: styles.panel };

refreshConnections();

return (
<PanelWrapper { ...wrapperProps }>
{ children }
Expand All @@ -64,7 +67,6 @@ const PublicizePanel = ( { prePublish, children } ) => {
/>
) }

<PublicizeConnectionVerify />
<PublicizeForm />
<SharePostRow />
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ import useSelectSocialMediaConnections from '../use-social-media-connections';
*/
export default function useRefreshConnections() {
const shouldAutoRefresh = useRef( false );
const isInitialRefresh = useRef( true );

const pageHasFocus = usePageVisibility();
const { refresh: refreshConnections } = useSelectSocialMediaConnections();

const initialRefresh = useDebounce( refreshConnections, 0 );
const debouncedRefresh = useDebounce( refreshConnections, 2000 );

return () => {
if ( isInitialRefresh.current ) {
initialRefresh();
isInitialRefresh.current = false;
}

if ( ! pageHasFocus ) {
shouldAutoRefresh.current = true;
debouncedRefresh.cancel();
Expand Down
Loading