made query into hook, converted more files to typescript
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
import axios from "../axiosInterceptor";
|
||||
|
||||
export const getFilesList = async ({ queryKey, pageParam }) => {
|
||||
console.log("quer", queryKey, pageParam);
|
||||
const [_key, { parent, search, sortBy, limit }] = queryKey;
|
||||
const response = await axios.get(
|
||||
`/file-service/list?parent=${parent}&sortby=${sortBy}&search=${search}&limit=${limit}`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { QueryFunctionContext } from "react-query";
|
||||
import axios from "../axiosInterceptor";
|
||||
|
||||
interface QueryKeyParams {
|
||||
parent: string;
|
||||
search?: string;
|
||||
sortBy?: string;
|
||||
limit?: number;
|
||||
startAtDate?: string;
|
||||
startAtName?: string;
|
||||
startAt?: boolean;
|
||||
}
|
||||
|
||||
export const getFilesList = async ({
|
||||
queryKey,
|
||||
pageParam,
|
||||
}: QueryFunctionContext<[string, QueryKeyParams]>) => {
|
||||
const [
|
||||
_key,
|
||||
{ parent = "/", search = "", sortBy = "date_desc", limit = 50 },
|
||||
] = queryKey;
|
||||
|
||||
const queryParams: QueryKeyParams = {
|
||||
parent,
|
||||
search,
|
||||
sortBy,
|
||||
limit,
|
||||
};
|
||||
|
||||
if (pageParam?.startAtDate && pageParam?.startAtName) {
|
||||
queryParams.startAtDate = pageParam.startAtDate;
|
||||
queryParams.startAtName = pageParam.startAtName;
|
||||
queryParams.startAt = true;
|
||||
}
|
||||
|
||||
const response = await axios.get(`/file-service/list`, {
|
||||
params: queryParams,
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
import axios from "../axiosInterceptor";
|
||||
|
||||
export const getFoldersList = async ({ queryKey }) => {
|
||||
const [_key, { parent, search, sortBy, limit }] = queryKey;
|
||||
const response = await axios.get(
|
||||
`/folder-service/list?parent=${parent}&sortby=${sortBy}&search=${search}&limit=${limit}`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
import { QueryFunctionContext } from "react-query";
|
||||
import axios from "../axiosInterceptor";
|
||||
|
||||
interface QueryKeyParams {
|
||||
parent: string;
|
||||
search?: string;
|
||||
sortBy?: string;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export const getFoldersList = async ({
|
||||
queryKey,
|
||||
}: QueryFunctionContext<[string, QueryKeyParams]>) => {
|
||||
const [_key, { parent, search, sortBy, limit }] = queryKey;
|
||||
const response = await axios.get(`/folder-service/list`, {
|
||||
params: {
|
||||
parent,
|
||||
search,
|
||||
sortBy,
|
||||
limit,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
Reference in New Issue
Block a user