Skip to content

Commit

Permalink
Prevent complete re rendering of the card.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvinb committed Oct 30, 2024
1 parent db10842 commit 3e4249c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ const ConnectAdsBody = ( {
setValue,
accountID,
} ) => {
const getAction = () => {
if ( isLoading ) {
return (
<LoadingLabel
text={ __( 'Connecting…', 'google-listings-and-ads' ) }
/>
);
}

if ( isConnected ) {
return <ConnectedIconLabel />;
}

if ( isConnected === null ) {
return <ConnectButton loading />;
}

return <ConnectButton accountID={ accountID } onClick={ onClick } />;
};

return (
<ContentButtonLayout>
<AdsAccountSelectControl
Expand All @@ -38,22 +58,8 @@ const ConnectAdsBody = ( {
autoSelectFirstOption={ true }
nonInteractive={ isConnected }
/>
{ isLoading ? (
<LoadingLabel
text={ __( 'Connecting…', 'google-listings-and-ads' ) }
/>
) : (
<>
{ isConnected ? (
<ConnectedIconLabel />
) : (
<ConnectButton
accountID={ accountID }
onClick={ onClick }
/>
) }
</>
) }

{ getAction() }
</ContentButtonLayout>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ const ConnectAds = ( { isEditing } ) => {
}
};

// If the accounts are still being fetched, we don't want to show the card.
if (
! hasFinishedResolutionForExistingAdsAccount ||
! hasFinishedResolutionForCurrentAccount ||
! accounts?.length
) {
if ( ! accounts?.length ) {
return null;
}

Expand Down

0 comments on commit 3e4249c

Please sign in to comment.