improvements do větve master před před 3 roky
| return ( | return ( | ||||
| <Card | <Card | ||||
| sx={{ | sx={{ | ||||
| ml: { xs: 2, md: 10 }, | |||||
| mr: { xs: 1, md: 10, lg: 1 }, | |||||
| backgroundColor: '#f2f2f2', | backgroundColor: '#f2f2f2', | ||||
| p: 2, | p: 2, | ||||
| mb: 2, | mb: 2, |
| import { Grid, Typography } from '@mui/material'; | |||||
| import { Typography } from '@mui/material'; | |||||
| import { Box } from '@mui/system'; | import { Box } from '@mui/system'; | ||||
| import { destroyCookie } from 'nookies'; | import { destroyCookie } from 'nookies'; | ||||
| import { useEffect } from 'react'; | import { useEffect } from 'react'; | ||||
| }; | }; | ||||
| return ( | return ( | ||||
| <Grid container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}> | |||||
| <Box sx={{ py: 10, height: '100%', width: '100%' }}> | |||||
| <StepTitle title="Items in Your Cart" breadcrumbsArray={['Cart']} /> | <StepTitle title="Items in Your Cart" breadcrumbsArray={['Cart']} /> | ||||
| <Grid item lg={8} xs={12} sx={{ mt: 2 }}> | |||||
| {mapProductsToDom()} | |||||
| </Grid> | |||||
| <Grid item lg={4} xs={12}> | |||||
| <Box sx={{ mr: { md: 12 }, mt: 2, ml: { xs: 2, md: 12, lg: 0 } }}> | |||||
| <Box | |||||
| sx={{ | |||||
| display: 'flex', | |||||
| flexDirection: { xs: 'column', lg: 'row' }, | |||||
| mr: { xs: 2, md: 12 }, | |||||
| ml: { xs: 2, md: 12 }, | |||||
| }} | |||||
| > | |||||
| <Box sx={{ mt: 2, mr: { lg: 2, minWidth: '65%' } }}> | |||||
| {mapProductsToDom()} | |||||
| </Box> | |||||
| <Box sx={{ mt: 2 }}> | |||||
| <OrderSummaryCard | <OrderSummaryCard | ||||
| data={{ totalPrice: totalPrice, totalQuantity: totalQuantity }} | data={{ totalPrice: totalPrice, totalQuantity: totalQuantity }} | ||||
| ></OrderSummaryCard> | ></OrderSummaryCard> | ||||
| </Box> | </Box> | ||||
| </Grid> | |||||
| </Grid> | |||||
| </Box> | |||||
| </Box> | |||||
| ); | ); | ||||
| }; | }; | ||||
| }; | }; | ||||
| return ( | return ( | ||||
| <Box container spacing={2} sx={{ py: 10, height: '100%', width: '100%' }}> | |||||
| <Box sx={{ py: 10, height: '100%', width: '100%' }}> | |||||
| <StepTitle | <StepTitle | ||||
| title="Items in Your Cart" | title="Items in Your Cart" | ||||
| breadcrumbsArray={['Cart', 'Checkout']} | breadcrumbsArray={['Cart', 'Checkout']} |
| import { Box } from '@mui/system'; | |||||
| import Head from 'next/head'; | |||||
| import { useState } from 'react'; | |||||
| import { useInfiniteProducts } from '../../hooks/useInfiniteQuery'; | |||||
| import FilterSort from '../filter-sort/FilterSort'; | |||||
| import LoadingSpinner from '../loader/basic-spinner/LoadSpinner'; | |||||
| import ProductsGrid from '../products-grid/ProductsGrid'; | |||||
| import ProductsHero from '../products-hero/ProductsHero'; | |||||
| const ProductsContent = () => { | |||||
| const [filter, setFilter] = useState(''); | |||||
| const [sort, setSort] = useState(''); | |||||
| const { data, isLoading, fetchNextPage, hasNextPage, isFetchingNextPage } = | |||||
| useInfiniteProducts(filter, sort); | |||||
| const handleProductTypeChange = (event) => { | |||||
| const filterText = event.target.value; | |||||
| setFilter(filterText); | |||||
| }; | |||||
| const handleSortChange = (event) => { | |||||
| const sort = event.target.value; | |||||
| setSort(sort); | |||||
| }; | |||||
| return ( | |||||
| <Box | |||||
| sx={{ | |||||
| display: 'flex', | |||||
| flexDirection: 'column', | |||||
| }} | |||||
| > | |||||
| <Head> | |||||
| <title>NextJS template</title> | |||||
| <meta name="description" content="Random data with pagination..." /> | |||||
| </Head> | |||||
| <ProductsHero /> | |||||
| <FilterSort | |||||
| handleProductTypeChange={handleProductTypeChange} | |||||
| productType={filter} | |||||
| sort={sort} | |||||
| handleSortChange={handleSortChange} | |||||
| /> | |||||
| {isLoading ? ( | |||||
| <LoadingSpinner /> | |||||
| ) : ( | |||||
| <ProductsGrid | |||||
| allProducts={data} | |||||
| sort={sort} | |||||
| productType={filter} | |||||
| fetchNextPage={fetchNextPage} | |||||
| hasNextPage={hasNextPage} | |||||
| isFetchingNextPage={isFetchingNextPage} | |||||
| /> | |||||
| )} | |||||
| </Box> | |||||
| ); | |||||
| }; | |||||
| export default ProductsContent; |
| width: 150, | width: 150, | ||||
| color: 'white', | color: 'white', | ||||
| ':hover': { | ':hover': { | ||||
| bgcolor: 'primary.main', // theme.palette.primary.main | |||||
| bgcolor: 'primary.main', | |||||
| color: 'white', | color: 'white', | ||||
| }, | }, | ||||
| }} | }} |
| import { useQuery } from '@tanstack/react-query'; | import { useQuery } from '@tanstack/react-query'; | ||||
| import { getProductData } from '../requests/products/producDataRequest'; | import { getProductData } from '../requests/products/producDataRequest'; | ||||
| import { getProductsByCategory } from '../requests/products/productsByCategoryRequest'; | |||||
| export const useFetchSingleProduct = (customID) => { | export const useFetchSingleProduct = (customID) => { | ||||
| return useQuery( | return useQuery( | ||||
| async () => await getProductData(customID) | async () => await getProductData(customID) | ||||
| ); | ); | ||||
| }; | }; | ||||
| export const useFetchSimilarProducts = (category) => { | |||||
| return useQuery( | |||||
| ['products', category], | |||||
| async () => await getProductsByCategory(category), | |||||
| { | |||||
| enabled: !!category, | |||||
| } | |||||
| ); | |||||
| }; | |||||
| export const useFetchProductsByCategory = (productType) => { | |||||
| return useQuery( | |||||
| ['filteredProducts', productType], | |||||
| async () => await getProductsByCategory(productType), | |||||
| { enabled: productType === 'Mug' || productType === 'Coffee' } | |||||
| ); | |||||
| }; |
| import { Box } from '@mui/system'; | |||||
| import Head from 'next/head'; | |||||
| import { useState } from 'react'; | |||||
| import FilterSort from '../../components/filter-sort/FilterSort'; | |||||
| import LoadingSpinner from '../../components/loader/basic-spinner/LoadSpinner'; | |||||
| import ProductsGrid from '../../components/products-grid/ProductsGrid'; | |||||
| import ProductsHero from '../../components/products-hero/ProductsHero'; | |||||
| import { useInfiniteProducts } from '../../hooks/useInfiniteQuery'; | |||||
| import ProductsContent from '../../components/products-content/ProductsContent'; | |||||
| const Products = () => { | const Products = () => { | ||||
| const [filter, setFilter] = useState(''); | |||||
| const [sort, setSort] = useState(''); | |||||
| const { data, isLoading, fetchNextPage, hasNextPage, isFetchingNextPage } = | |||||
| useInfiniteProducts(filter, sort); | |||||
| const handleProductTypeChange = (event) => { | |||||
| const filterText = event.target.value; | |||||
| setFilter(filterText); | |||||
| }; | |||||
| const handleSortChange = (event) => { | |||||
| const sort = event.target.value; | |||||
| setSort(sort); | |||||
| }; | |||||
| return ( | |||||
| <Box | |||||
| sx={{ | |||||
| display: 'flex', | |||||
| flexDirection: 'column', | |||||
| }} | |||||
| > | |||||
| <Head> | |||||
| <title>NextJS template</title> | |||||
| <meta name="description" content="Random data with pagination..." /> | |||||
| </Head> | |||||
| <ProductsHero /> | |||||
| <FilterSort | |||||
| handleProductTypeChange={handleProductTypeChange} | |||||
| productType={filter} | |||||
| sort={sort} | |||||
| handleSortChange={handleSortChange} | |||||
| /> | |||||
| {isLoading ? ( | |||||
| <LoadingSpinner /> | |||||
| ) : ( | |||||
| <ProductsGrid | |||||
| allProducts={data} | |||||
| sort={sort} | |||||
| productType={filter} | |||||
| fetchNextPage={fetchNextPage} | |||||
| hasNextPage={hasNextPage} | |||||
| isFetchingNextPage={isFetchingNextPage} | |||||
| /> | |||||
| )} | |||||
| </Box> | |||||
| ); | |||||
| return <ProductsContent />; | |||||
| }; | }; | ||||
| export default Products; | export default Products; |