66 lines
1.5 KiB
TypeScript
66 lines
1.5 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;
|
|
}[];
|
|
main_categories: Category[];
|
|
top_seller_products: ProductListItem[];
|
|
lot_of_discount_products: ProductListItem[];
|
|
most_viewed_products: ProductListItem[];
|
|
trends_products: ProductListItem[];
|
|
products: ProductListItem[];
|
|
difreance_section: {
|
|
image1: string;
|
|
image2: string;
|
|
title1: string;
|
|
title2: string;
|
|
description1: string;
|
|
description2: string;
|
|
link1: string;
|
|
link2: string;
|
|
video1: string;
|
|
video2: string;
|
|
};
|
|
show_case_slider: {
|
|
id: number;
|
|
title: string;
|
|
description: string;
|
|
link: string;
|
|
image1: string;
|
|
image2: string;
|
|
image3: string;
|
|
background_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;
|