Refactored useQuery functions.

This commit is contained in:
Mike Cao 2023-12-01 20:27:59 -08:00
parent be550cc440
commit b578162cb6
33 changed files with 179 additions and 151 deletions

View file

@ -35,8 +35,8 @@ export function MetricsTable({
const { get, useQuery } = useApi();
const { dir } = useLocale();
const { data, isLoading, isFetched, error } = useQuery(
[
const { data, isLoading, isFetched, error } = useQuery({
queryKey: [
'websites:metrics',
{
websiteId,
@ -53,11 +53,13 @@ export function MetricsTable({
city,
},
],
() => {
queryFn: () => {
const filters = { url, title, referrer, os, browser, device, country, region, city };
filters[type] = undefined;
onDataLoad?.();
return get(`/websites/${websiteId}/metrics`, {
type,
startAt: +startDate,
@ -65,8 +67,8 @@ export function MetricsTable({
...filters,
});
},
{ onSuccess: onDataLoad, retryDelay: delay || DEFAULT_ANIMATION_DURATION },
);
retryDelay: delay || DEFAULT_ANIMATION_DURATION,
});
const filteredData = useMemo(() => {
if (data) {