File size: 734 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { fetchBasicMetrics, fetchPerformanceInsights } from '../../data/site-profiler';
import type { UrlPerformanceInsights } from '../../data/site-profiler';
import type { Query } from '@tanstack/react-query';

export const basicMetricsQuery = ( url: string ) => ( {
	queryKey: [ 'performance', url, 'basic-metrics' ],
	queryFn: () => fetchBasicMetrics( url ),
} );

export const performanceInsightsQuery = ( url: string, token: string ) => ( {
	queryKey: [ 'performance', url, token ],
	queryFn: () => {
		return fetchPerformanceInsights( url, token );
	},
	refetchInterval: ( query: Query< UrlPerformanceInsights > ) => {
		if ( query.state.data?.pagespeed?.status === 'completed' ) {
			return false;
		}
		return 5000;
	},
} );