Skip to content

Commit bb66758

Browse files
committed
Simplify logic for selecting sites, fix typo
1 parent 014d956 commit bb66758

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/modules/sync/index.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
useConnectedSitesOperations,
2626
connectedSitesSelectors,
2727
connectedSitesActions,
28-
loadAllConnectedSites,
2928
} from 'src/stores/sync';
3029
import type { SyncSite } from 'src/hooks/use-fetch-wpcom-sites/types';
3130
import type { SyncModalMode } from 'src/modules/sync/types';
@@ -42,7 +41,7 @@ function SiteSyncDescription( { children }: PropsWithChildren ) {
4241
</div>
4342
<div className="max-w-[40ch] text-a8c-gray-70 a8c-body">
4443
{ __(
45-
'Launch your existing WordPress.com or Jetpack-activated Pressable sites, or import an exisiting one. Then, share your work with the world.'
44+
'Launch your existing WordPress.com or Jetpack-activated Pressable sites, or import an existing one. Then, share your work with the world.'
4645
) }
4746
</div>
4847
<div className="mt-6">
@@ -153,14 +152,9 @@ export function ContentTabSync( { selectedSite }: { selectedSite: SiteDetails }
153152
return <NoAuthSyncTab />;
154153
}
155154

156-
const handleConnect = async ( newConnectedSite: SyncSite ): Promise< SyncSite | undefined > => {
155+
const handleConnect = async ( newConnectedSite: SyncSite ) => {
157156
try {
158157
await connectSite( newConnectedSite );
159-
160-
await dispatch( loadAllConnectedSites() );
161-
// Return the connected site with full metadata, or fallback to the original site
162-
const connectedSite = connectedSites.find( ( site ) => site.id === newConnectedSite.id );
163-
return connectedSite || newConnectedSite;
164158
} catch ( error ) {
165159
getIpcApi().showErrorMessageBox( {
166160
title: __( 'Failed to connect to site' ),
@@ -196,19 +190,14 @@ export function ContentTabSync( { selectedSite }: { selectedSite: SiteDetails }
196190
return;
197191
}
198192

199-
const isAlreadyConnected = connectedSites.some( ( site ) => site.id === siteId );
200-
if ( ! isAlreadyConnected ) {
201-
const connectedSite = await handleConnect( selectedSiteFromList );
202-
if ( ! connectedSite ) {
203-
return;
204-
}
205-
}
206-
const siteToUse = connectedSites.find( ( site ) => site.id === siteId ) || selectedSiteFromList;
207-
208-
dispatch( connectedSitesActions.closeModal() );
193+
await handleConnect( selectedSiteFromList );
209194

210195
if ( mode === 'push' || mode === 'pull' ) {
211-
setModalState( ( prev ) => ( { ...prev, mode: mode, selectedRemoteSite: siteToUse } ) );
196+
setModalState( ( prev ) => ( {
197+
...prev,
198+
mode: mode,
199+
selectedRemoteSite: selectedSiteFromList,
200+
} ) );
212201
} else {
213202
setModalState( ( prev ) => ( { ...prev, mode: null } ) );
214203
}

0 commit comments

Comments
 (0)