Basis for Upstreams UI

This commit is contained in:
Jamie Curnow
2023-01-10 11:46:40 +10:00
parent 7ea64c46e9
commit 560f3d9b29
13 changed files with 411 additions and 0 deletions

View File

@ -8,5 +8,6 @@ export * from "./useHealth";
export * from "./useHosts";
export * from "./useNginxTemplates";
export * from "./useSettings";
export * from "./useUpstreams";
export * from "./useUser";
export * from "./useUsers";

View File

@ -0,0 +1,41 @@
import {
getUpstreams,
HostsResponse,
tableSortToAPI,
tableFiltersToAPI,
} from "api/npm";
import { useQuery } from "react-query";
const fetchUpstreams = (
offset = 0,
limit = 10,
sortBy?: any,
filters?: any,
) => {
return getUpstreams(
offset,
limit,
tableSortToAPI(sortBy),
tableFiltersToAPI(filters),
);
};
const useUpstreams = (
offset = 0,
limit = 10,
sortBy?: any,
filters?: any,
options = {},
) => {
return useQuery<HostsResponse, Error>(
["upstreams", { offset, limit, sortBy, filters }],
() => fetchUpstreams(offset, limit, sortBy, filters),
{
keepPreviousData: true,
staleTime: 15 * 1000, // 15 seconds
...options,
},
);
};
export { fetchUpstreams, useUpstreams };