Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions src/hooks/use-site-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ export function SiteDetailsProvider( { children }: SiteDetailsProviderProps ) {
);
} );

useIpcListener( 'user-data-updated', async () => {
const updatedSites = await getIpcApi().getSiteDetails();
setSites( updatedSites );

// Handle case where selected site was deleted externally
if ( selectedSiteId && ! updatedSites.find( ( site ) => site.id === selectedSiteId ) ) {
setSelectedSiteId( updatedSites.length ? updatedSites[ 0 ].id : '' );
}
} );

const toggleLoadingServerForSite = useCallback( ( siteId: string ) => {
setLoadingServer( ( currentLoading ) => ( {
...currentLoading,
Expand Down
14 changes: 13 additions & 1 deletion src/ipc-handlers.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a concern for a later PR, but I think we should reconsider storing a global list of SiteServer instances in the node process. The CLI (or pm2, really) will soon be the source of truth for whether a server is running. It might make more sense to treat server instances as ephemeral variables in the node process, always reading from disk or the CLI whenever the client process queries them.

Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ function mergeSiteDetailsWithRunningDetails( sites: SiteDetails[] ): SiteDetails
return sites.map( ( site ) => {
const server = SiteServer.get( site.id );
if ( server ) {
return server.details;
// Merge fresh data from disk with running state from server
// This ensures external changes (e.g., from CLI) are reflected
if ( server.details.running ) {
return {
...site,
running: true as const,
url: server.details.url,
};
}
return {
...site,
running: false as const,
};
}
return site;
} );
Expand Down
Loading