-
Notifications
You must be signed in to change notification settings - Fork 51
Implement RTK Query approach for fetching wpcom sites #2132
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
base: trunk
Are you sure you want to change the base?
Changes from 9 commits
c4efc6c
7d8fd66
ba89f0d
ee7ea22
afd3fbf
d7113b1
9a6f74f
7d0b2a5
b09206b
427d3ab
63cc6b8
48ffd67
7e1bbdb
c86048c
b134968
5610e0e
5079edf
99a6b55
5cfc0f2
8fa10dd
61e8a4b
a2fd40a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. I suggest moving more of this logic to connectSite: builder.mutation<
SyncSite[],
{ remoteSiteId: number; localSiteId: string; userId?: number }
>( {
queryFn: async ( { remoteSiteId, localSiteId, userId }, api ) => {
const connectedSites = await getIpcApi().getConnectedWpcomSites( localSiteId );
const { data: remoteSites = [] } = await api.dispatch(
wpcomSitesApi.endpoints.getWpComSites.initiate( {
connectedSiteIds: connectedSites.map( ( site ) => site.id ),
userId,
} )
);
const siteToConnect = remoteSites.find( ( site ) => site.id === remoteSiteId );
if ( ! siteToConnect ) {
return {
error: { status: 'CUSTOM_ERROR', error: 'Site not found in WordPress.com sites' },
};
}
await getIpcApi().connectWpcomSites( [
{
sites: [ siteToConnect ],
localSiteId,
},
] );
const actualConnectedSites = await getIpcApi().getConnectedWpcomSites( localSiteId );
return { data: actualConnectedSites };
},This would allow us to shorten this hook significantly: export function useListenDeepLinkConnection() {
const [ connectSite ] = useConnectSiteMutation();
const { selectedSite, setSelectedSiteId } = useSiteDetails();
const { setSelectedTab, selectedTab } = useContentTabs();
const { user } = useAuth();
useIpcListener( 'sync-connect-site', async ( _event, { remoteSiteId, studioSiteId } ) => {
if ( selectedSite?.id && selectedSite.id !== studioSiteId ) {
// Select studio site that started the sync
setSelectedSiteId( studioSiteId );
}
await connectSite( { remoteSiteId, localSiteId: studioSiteId, userId: user?.id } );
if ( selectedTab !== 'sync' ) {
// Switch to sync tab
setSelectedTab( 'sync' );
}
} );
}
Contributor
Author
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. Thanks for the suggestion, I will work on that
Contributor
Author
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. I have been working on this, but I have found that this will trigger an additional call to the What do you think about tackling this specific refactor as a follow-up and progressing with the current changes? |
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.
This is a lint fix, unrelated to this PR