Skip to content

Commit 48c1f6e

Browse files
committed
refactor: move homepage components to its route
1 parent 946fac3 commit 48c1f6e

File tree

14 files changed

+86
-104
lines changed

14 files changed

+86
-104
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use client';
2+
3+
import { GetAllProductsQuery } from '@/graphql/types/graphql';
4+
import { Card, CardContent, CardHeader, useTheme } from '@mui/material';
5+
import { useTranslations } from 'next-intl';
6+
import { FC } from 'react';
7+
import { Swiper, SwiperSlide } from 'swiper/react';
8+
import { Autoplay, Navigation } from 'swiper/modules';
9+
import { VariableProductItem } from '@/components/VariableProductItem';
10+
11+
export interface BestSellingProductsProps {
12+
items?: NonNullable<GetAllProductsQuery['products']>['nodes'];
13+
}
14+
const BestSellingProducts: FC<BestSellingProductsProps> = ({ items }) => {
15+
const t = useTranslations();
16+
const theme = useTheme();
17+
18+
return (
19+
<Card variant="outlined">
20+
<CardHeader
21+
title={t('header.navigation.bestSelling')}
22+
sx={{
23+
textAlign: 'center',
24+
}}
25+
/>
26+
<CardContent>
27+
<Swiper
28+
dir={theme.direction}
29+
navigation={true}
30+
modules={[Autoplay, Navigation]}
31+
slidesPerView={1}
32+
breakpoints={{
33+
[theme.breakpoints.values.xs]: {
34+
slidesPerView: 1,
35+
spaceBetween: 16,
36+
},
37+
[theme.breakpoints.values.sm]: {
38+
slidesPerView: 2,
39+
spaceBetween: 16,
40+
},
41+
[theme.breakpoints.values.md]: {
42+
slidesPerView: 5,
43+
spaceBetween: 16,
44+
},
45+
[theme.breakpoints.values.lg]: {
46+
slidesPerView: 6,
47+
spaceBetween: 16,
48+
},
49+
}}
50+
spaceBetween={theme.spacing(2)}
51+
>
52+
{items?.map((product) => {
53+
if (product.__typename === 'VariableProduct') {
54+
return (
55+
<SwiperSlide
56+
key={product.databaseId}
57+
style={{
58+
height: 'auto',
59+
boxSizing: 'border-box',
60+
}}
61+
>
62+
<VariableProductItem data={product} />
63+
</SwiperSlide>
64+
);
65+
}
66+
})}
67+
</Swiper>
68+
</CardContent>
69+
</Card>
70+
);
71+
};
72+
73+
export default BestSellingProducts;

src/components/MainCategories/MainCategories.tsx renamed to src/app/[locale]/(main)/(container)/(homepage)/components/MainCategories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChevronLeft } from '@mui/icons-material';
44
import { Box, Grid, Link, Stack } from '@mui/material';
55
import { grey } from '@mui/material/colors';
66
import React, { FC } from 'react';
7-
import Image from '../common/Image';
7+
import Image from '../../../../../../components/common/Image';
88

99
export interface IMainCategory {
1010
id: number | string;

src/components/HomePageSlider/HomePageSlider.tsx renamed to src/app/[locale]/(main)/(container)/(homepage)/components/MainSlider/MainSlider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { Autoplay, Navigation, Pagination } from 'swiper/modules';
88
import { SliderItem } from './components/SliderItem';
99
import { ISliderItem } from './types';
1010

11-
export interface CarouselProps {
11+
export interface MainSliderProps {
1212
items?: ISliderItem[];
1313
}
1414

15-
const MySwiper: FC<CarouselProps> = ({ items }) => {
15+
const MainSlider: FC<MainSliderProps> = ({ items }) => {
1616
const theme = useTheme();
1717
return (
1818
<Swiper
@@ -43,4 +43,4 @@ const MySwiper: FC<CarouselProps> = ({ items }) => {
4343
);
4444
};
4545

46-
export default MySwiper;
46+
export default MainSlider;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as MainSlider } from './MainSlider';

src/app/[locale]/(main)/(container)/(homepage)/page.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import BestSellingProducts from '@/components/BestSellingProducts/BestSellingProducts';
2-
import { HomePageSlider } from '@/components/HomePageSlider';
3-
import { ISliderItem } from '@/components/HomePageSlider/types';
4-
import { MainCategories } from '@/components/MainCategories';
51
import { getClient } from '@/graphql/clients/serverSideClient';
62
import { GET_MAIN_CATEGORIES } from '@/graphql/queries/categories';
73
import { GET_VARIABLE_PRODUCTS_QUERY } from '@/graphql/queries/products';
@@ -15,9 +11,13 @@ import {
1511
import { Sleep } from '@/services/common';
1612
import { bestSellingSortOption } from '@/static/sortOptions';
1713
import { Grid } from '@mui/material';
14+
import { MainSlider } from './components/MainSlider';
15+
import MainCategories from './components/MainCategories';
16+
import BestSellingProducts from './components/BestSellingProducts';
17+
import { ISliderItem } from './components/MainSlider/types';
1818

1919
const getSliders = async () => {
20-
await Sleep(51111000);
20+
await Sleep(2000);
2121
const { data } = await getClient().query<GetHomePageSlidersQuery>({
2222
query: GET_HOMEPAGE_SLIDERS,
2323
});
@@ -79,7 +79,7 @@ export default async function Home() {
7979
return (
8080
<Grid container spacing={2}>
8181
<Grid item xs={12}>
82-
<HomePageSlider items={sliders} />
82+
<MainSlider items={sliders} />
8383
</Grid>
8484
<Grid item xs={12}>
8585
<MainCategories items={categories} />

src/components/BaseLayout/BaseLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Footer } from '@/components/Footer';
22
import { Header } from '@/components/Header';
3-
import { ISliderItem } from '@/components/HomePageSlider/types';
3+
import { ISliderItem } from '@/app/[locale]/(main)/(container)/(homepage)/components/MainSlider/types';
44
import { getClient } from '@/graphql/clients/serverSideClient';
55
import { GET_PUBLISHED_PAGES_LIST } from '@/graphql/queries/pages';
66
import { GET_TOP_BANNER } from '@/graphql/queries/sliders';

src/components/BestSellingProducts/BestSellingProducts.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)