Updated
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
// 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": {
|
||||||
|
"id": number,
|
||||||
|
"name": string,
|
||||||
|
"icon": string,
|
||||||
|
"product_count": number,
|
||||||
|
}[],
|
||||||
|
"products": Product[],
|
||||||
|
"difreance_section": {
|
||||||
|
"image1": string,
|
||||||
|
"image2": string,
|
||||||
|
"title1": string,
|
||||||
|
"title2": string,
|
||||||
|
"description1": string,
|
||||||
|
"description2": string,
|
||||||
|
"link1": string,
|
||||||
|
"link2": 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;
|
||||||
Reference in New Issue
Block a user