diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index df92de2d3..4b839e92e 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -345,6 +345,9 @@ export function getTaskById( export const getTasks = () => axios.get(TASKS).then((response) => response.data); +export const getServerTasks = (params: HubRequestParams = {}) => + getHubPaginatedResult(TASKS, params); + export const deleteTask = (id: number) => axios.delete(`${TASKS}/${id}`); export const cancelTask = (id: number) => diff --git a/client/src/app/queries/tasks.ts b/client/src/app/queries/tasks.ts index 9d07bd42c..b92e4ebd8 100644 --- a/client/src/app/queries/tasks.ts +++ b/client/src/app/queries/tasks.ts @@ -1,7 +1,14 @@ import { useMutation, useQuery } from "@tanstack/react-query"; -import { cancelTask, deleteTask, getTaskById, getTasks } from "@app/api/rest"; +import { + cancelTask, + deleteTask, + getServerTasks, + getTaskById, + getTasks, +} from "@app/api/rest"; import { universalComparator } from "@app/utils/utils"; +import { HubPaginatedResult, HubRequestParams, Task } from "@app/api/models"; interface FetchTasksFilters { addon?: string; @@ -50,6 +57,26 @@ export const useFetchTasks = ( }; }; +export const useServerTasks = (params: HubRequestParams = {}) => { + const { data, isLoading, error, refetch } = useQuery({ + queryKey: [TasksQueryKey, params], + queryFn: async () => await getServerTasks(params), + onError: (error) => console.log("error, ", error), + keepPreviousData: true, + }); + + return { + result: { + data: data?.data, + total: data?.total ?? 0, + params: data?.params ?? params, + } as HubPaginatedResult, + isFetching: isLoading, + fetchError: error, + refetch, + }; +}; + export const useDeleteTaskMutation = ( onSuccess: () => void, onError: (err: Error | null) => void