Files
hossein-por-shop/frontend/composables/api/home/useHomeData.ts
T
marzban-dev 95c698f357 Updated
2025-03-04 20:42:30 +03:30

58 lines
1.2 KiB
TypeScript

// imports
import { useQuery } from "@tanstack/vue-query";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetHomeDataResponse = {
"sliders": {
"id": number,
"link": string,
"title": string,
"description": string,
"image": string | null,
"video": string | null
}[],
"sub_categories": SubCategory[],
"products": Product[],
"difreance_section": {
"image1": string,
"image2": string,
"title1": string,
"title2": string,
"description1": string,
"description2": string,
"link1": string,
"link2": string
},
"show_case_slider" : {
"id": number,
"title": string,
"description": string,
"link": string,
"image": string,
}[]
};
const useHomeData = () => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleHomeData = async () => {
const { data } = await axios.get<GetHomeDataResponse>(`${API_ENDPOINTS.home}`);
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.home],
queryFn: () => handleHomeData()
});
};
export default useHomeData;