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.
50 lines
1.6 KiB
50 lines
1.6 KiB
import type { NextPage } from 'next';
|
|
import React from 'react';
|
|
import { useSelector } from 'react-redux'
|
|
import { MainLayout } from '../layouts/Customer';
|
|
import { CardStock, SkeletonStock, BoxScroll, MottoBlock, CategoriesButton, CategoriesSkeleton, Box } from '../components';
|
|
import { useAppDispatch } from '../redux/store';
|
|
|
|
import { fetchStoke } from '../redux/stoke/stock';
|
|
import { selectStokeData } from '../redux/stoke/selectors';
|
|
|
|
import { fetchCategories } from '../redux/categories/stock';
|
|
import { selectCategoriesData } from '../redux/categories/selectors';
|
|
|
|
|
|
const Home: NextPage = () => {
|
|
const dispatch = useAppDispatch();
|
|
|
|
React.useEffect(() => {
|
|
dispatch( fetchStoke() );
|
|
dispatch( fetchCategories() );
|
|
}, [1]);
|
|
|
|
const { items, status } = useSelector(selectStokeData);
|
|
const { categories_items, categories_status } = useSelector(selectCategoriesData);
|
|
|
|
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} />);
|
|
|
|
return (
|
|
<MainLayout>
|
|
<BoxScroll>
|
|
{status === 'loading' ? skeletonsStoke : stokes}
|
|
</BoxScroll>
|
|
<BoxScroll>
|
|
<MottoBlock/>
|
|
</BoxScroll>
|
|
<BoxScroll>
|
|
{categories_status === 'loading' ? categoriesSkeleton : categories}
|
|
</BoxScroll>
|
|
<Box>
|
|
|
|
</Box>
|
|
</MainLayout>
|
|
)
|
|
}
|
|
|
|
export default Home
|
|
|