You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
import type { NextPage } from 'next';
|
|
import React from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { MainLayout } from '../layouts/Customer';
|
|
import { useRouter } from "next/router";
|
|
|
|
import { CardStock,
|
|
SkeletonStock,
|
|
MottoBlock,
|
|
CategoriesButton,
|
|
CategoriesSkeleton,
|
|
PizzaBlock,
|
|
PizzaSkeleton,
|
|
Description,
|
|
DeliveryArea } from '../components/customer/pages/index/block';
|
|
|
|
import { BoxScroll,
|
|
Box } from '../components/customer/containers';
|
|
|
|
|
|
import { PizzaCard } from '../components/customer/pages/index/modals'
|
|
|
|
import { useAppDispatch } from '../redux/store';
|
|
import { fetchStoke, selectStokeData } from '../redux/stoke/';
|
|
import { fetchCategories, selectCategoriesData } from '../redux/categories';
|
|
import { fetchPizza, selectPizzaData } from '../redux/pizza';
|
|
|
|
|
|
|
|
const Home: NextPage = () => {
|
|
const dispatch = useAppDispatch();
|
|
let router = useRouter();
|
|
console.log(router.query.pizza, 'pizza');
|
|
React.useEffect(() => {
|
|
dispatch( fetchStoke() );
|
|
dispatch( fetchCategories() );
|
|
dispatch( fetchPizza() );
|
|
}, [1]);
|
|
|
|
const { items, status } = useSelector(selectStokeData);
|
|
const { categories_items, categories_status } = useSelector(selectCategoriesData);
|
|
const { pizza_items, pizza_status } = useSelector(selectPizzaData);
|
|
|
|
const stokes = items.map((obj, index) => <CardStock key={index} {...obj} />);
|
|
const skeletonsStoke = [...new Array(4)].map((_, index) => <SkeletonStock key={index} />);
|
|
|
|
const categories = categories_items.map((obj, index) => <CategoriesButton key={index} {...obj}/> );
|
|
const categoriesSkeleton = [...new Array(6)].map((_, index) => <CategoriesSkeleton key={index} />);
|
|
|
|
const pizza = pizza_items.map((obj, index) => <PizzaBlock key={index} {...obj}/> );
|
|
const pizzaSkeleton = [...new Array(6)].map((_, index) => <PizzaSkeleton key={index} />);
|
|
|
|
return (
|
|
<MainLayout>
|
|
<BoxScroll>
|
|
{status === 'loading' ? skeletonsStoke : stokes}
|
|
</BoxScroll>
|
|
<MottoBlock/>
|
|
<BoxScroll>
|
|
{categories_status === 'loading' ? categoriesSkeleton : categories}
|
|
</BoxScroll>
|
|
<Box>
|
|
{pizza_status === 'loading' ? pizzaSkeleton : pizza}
|
|
</Box>
|
|
<Box>
|
|
<DeliveryArea/>
|
|
<Description/>
|
|
</Box>
|
|
{router.query.pizza && (
|
|
<PizzaCard id={router.query.pizza} />
|
|
)}
|
|
|
|
</MainLayout>
|
|
)
|
|
}
|
|
|
|
export default Home;
|
|
|