made query into hook, converted more files to typescript

This commit is contained in:
subnub
2024-06-19 18:44:42 -04:00
parent 49e6bab79c
commit 55142b29f9
13 changed files with 127 additions and 127 deletions
-10
View File
@@ -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;
};
+40
View File
@@ -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;
};
-9
View File
@@ -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;
};
+24
View File
@@ -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;
};