Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -20,22 +20,11 @@ export type GetProductsFilters = {
|
||||
|
||||
// composable
|
||||
|
||||
const useGetProducts = (params?: GetProductsFilters) => {
|
||||
const useGetProducts = (params?: ComputedRef<GetProductsFilters>) => {
|
||||
// state
|
||||
|
||||
const { $axios: axios } = useNuxtApp();
|
||||
|
||||
const {
|
||||
search,
|
||||
sort,
|
||||
in_stock,
|
||||
has_discount,
|
||||
category,
|
||||
price_gte,
|
||||
price_lte,
|
||||
page,
|
||||
} = toRefs(params as GetProductsFilters);
|
||||
|
||||
// methods
|
||||
|
||||
const handleGetProducts = async (params?: GetProductsFilters) => {
|
||||
@@ -50,7 +39,7 @@ const useGetProducts = (params?: GetProductsFilters) => {
|
||||
category: params?.category,
|
||||
price_gte: params?.price_gte,
|
||||
price_lte: params?.price_lte,
|
||||
offset: params?.page ? Number(params.page) * 9 - 9 : 0,
|
||||
offset: Number(params?.page) * 9 - 9,
|
||||
limit: 9,
|
||||
},
|
||||
}
|
||||
@@ -61,18 +50,8 @@ const useGetProducts = (params?: GetProductsFilters) => {
|
||||
|
||||
return useQuery({
|
||||
staleTime: 60 * 1000,
|
||||
queryKey: [
|
||||
QUERY_KEYS.products,
|
||||
search,
|
||||
sort,
|
||||
in_stock,
|
||||
has_discount,
|
||||
category,
|
||||
price_gte,
|
||||
price_lte,
|
||||
page,
|
||||
],
|
||||
queryFn: () => handleGetProducts(params),
|
||||
queryKey: [QUERY_KEYS.products, params],
|
||||
queryFn: () => handleGetProducts(params?.value),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user