diff --git a/Lab5/src/components/banner/Banner.css b/Lab5/src/components/banner/Banner.css deleted file mode 100644 index a15107b..0000000 --- a/Lab5/src/components/banner/Banner.css +++ /dev/null @@ -1,25 +0,0 @@ -#banner { - margin: 2px; - display: flex; - align-items: center; - flex-direction: column; -} - -#banner img { - border: 1px solid #3c3c3f; - border-radius: 5px; -} - -#banner img.banner-show { - width: 100%; - opacity: 1; - transition: opacity 1s, visibility 0s; -} - -#banner img.banner-hide { - height: 0; - width: 0; - opacity: 0; - visibility: hidden; - transition: opacity 1s, visibility 0s 1s; -} \ No newline at end of file diff --git a/Lab5/src/components/banner/Banner.jsx b/Lab5/src/components/banner/Banner.jsx deleted file mode 100644 index d636661..0000000 --- a/Lab5/src/components/banner/Banner.jsx +++ /dev/null @@ -1,17 +0,0 @@ -import './Banner.css'; -import useBannerHook from './BannerHook'; - -const Banner = () => { - const { banners, getBannerClass } = useBannerHook(); - - return ( - - ); -}; - -export default Banner; diff --git a/Lab5/src/components/banner/BannerHook.js b/Lab5/src/components/banner/BannerHook.js deleted file mode 100644 index 1813699..0000000 --- a/Lab5/src/components/banner/BannerHook.js +++ /dev/null @@ -1,36 +0,0 @@ -import { useEffect, useState } from 'react'; -import banner1 from '../../assets/banner1.png'; -import banner2 from '../../assets/banner2.png'; -import banner3 from '../../assets/banner3.png'; - -const useBannerHook = () => { - const [currentBanner, setCurrentBanner] = useState(0); - const banners = [banner1, banner2, banner3]; - - const getBannerClass = (index) => { - return currentBanner === index ? 'banner-show' : 'banner-hide'; - }; - - useEffect(() => { - const bannerInterval = setInterval( - () => { - console.info('Banner changed'); - let current = currentBanner + 1; - if (current === banners.length) { - current = 0; - } - setCurrentBanner(current); - }, - 5000, - ); - return () => clearInterval(bannerInterval); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - return { - banners, - getBannerClass, - }; -}; - -export default useBannerHook; diff --git a/Lab5/src/components/cart/Cart.css b/Lab5/src/components/cart/Cart.css deleted file mode 100644 index 8d9a13f..0000000 --- a/Lab5/src/components/cart/Cart.css +++ /dev/null @@ -1,8 +0,0 @@ -.cart-image { - width: 3.1rem; - padding: .25rem; -} - -.cart-item { - height: auto; -} \ No newline at end of file diff --git a/Lab5/src/components/cart/Cart.jsx b/Lab5/src/components/cart/Cart.jsx deleted file mode 100644 index f617c17..0000000 --- a/Lab5/src/components/cart/Cart.jsx +++ /dev/null @@ -1,59 +0,0 @@ -import { Button, ButtonGroup, Card } from 'react-bootstrap'; -import { DashLg, PlusLg, XLg } from 'react-bootstrap-icons'; -import imgPlaceholder from '../../assets/200.png'; -import './Cart.css'; -import useCart from './CartHook'; - -const Cart = () => { - const { - cart, - getCartSum, - addToCart, - removeFromCart, - clearCart, - } = useCart(); - - return ( -
-
- Корзина - -
- { - cart.map((cartItem) => - - -
- Cart Image - {cartItem.type.name} -
-
-
- {cartItem.price} - {' * '} - {cartItem.count} - {' = '} - {parseFloat(cartItem.price * cartItem.count).toFixed(2)} -
- - - - -
-
-
) - } -
- Итого: {getCartSum()} ₽ -
-
- ); -}; - -export default Cart; diff --git a/Lab5/src/components/cart/CartContext.jsx b/Lab5/src/components/cart/CartContext.jsx deleted file mode 100644 index 9c995ec..0000000 --- a/Lab5/src/components/cart/CartContext.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import PropTypes from 'prop-types'; -import { - createContext, - useEffect, - useReducer, -} from 'react'; -import { cartReducer, loadCart, saveCart } from './CartReducer'; - -const CartContext = createContext(null); - -export const CartProvider = ({ children }) => { - const [cart, dispatch] = useReducer(cartReducer, [], loadCart); - - useEffect(() => { - saveCart(cart || []); - }, [cart]); - - return ( - - {children} - - ); -}; - -CartProvider.propTypes = { - children: PropTypes.node, -}; - -export default CartContext; diff --git a/Lab5/src/components/cart/CartHook.js b/Lab5/src/components/cart/CartHook.js deleted file mode 100644 index b899b45..0000000 --- a/Lab5/src/components/cart/CartHook.js +++ /dev/null @@ -1,26 +0,0 @@ -import { useContext } from 'react'; -import CartContext from './CartContext.jsx'; -import { cartAdd, cartClear, cartRemove } from './CartReducer'; - -const useCart = () => { - const { cart, dispatch } = useContext(CartContext); - - const cartSum = () => { - return parseFloat( - cart?.reduce((sum, cartItem) => { - return sum + (cartItem.price * cartItem.count); - }, 0) - ?? 0, - ).toFixed(2); - }; - - return { - cart, - getCartSum: () => cartSum(), - addToCart: (item) => dispatch(cartAdd(item)), - removeFromCart: (item) => dispatch(cartRemove(item)), - clearCart: () => dispatch(cartClear()), - }; -}; - -export default useCart; diff --git a/Lab5/src/components/cart/CartReducer.js b/Lab5/src/components/cart/CartReducer.js deleted file mode 100644 index f68e140..0000000 --- a/Lab5/src/components/cart/CartReducer.js +++ /dev/null @@ -1,71 +0,0 @@ -const setCartCount = (cart, item, value) => { - return cart.map((cartItem) => { - if (cartItem.id === item.id) { - return { ...cartItem, count: cartItem.count + value }; - } - return cartItem; - }); -}; - -const addToCart = (cart, item) => { - const existsItem = cart.find((cartItem) => cartItem.id === item.id); - if (existsItem !== undefined) { - return setCartCount(cart, item, 1); - } - return [...cart, { ...item, count: 1 }]; -}; - -const removeFromCart = (cart, item) => { - const existsItem = cart.find((cartItem) => cartItem.id === item.id); - if (existsItem !== undefined && existsItem.count > 1) { - return setCartCount(cart, item, -1); - } - return cart.filter((cartItem) => cartItem.id !== item.id); -}; - -const CART_KEY = 'localCart'; -const CART_ADD = 'cart/add'; -const CART_REMOVE = 'cart/remove'; -const CART_CLEAR = 'cart/clear'; - -export const saveCart = (cart) => { - localStorage.setItem(CART_KEY, JSON.stringify(cart)); -}; - -export const loadCart = (initialValue = []) => { - const cartData = localStorage.getItem(CART_KEY); - if (cartData) { - return JSON.parse(cartData); - } - return initialValue; -}; - -export const cartReducer = (cart, action) => { - const { item } = action; - switch (action.type) { - case CART_ADD: { - return addToCart(cart, item); - } - case CART_REMOVE: { - return removeFromCart(cart, item); - } - case CART_CLEAR: { - return []; - } - default: { - throw Error(`Unknown action: ${action.type}`); - } - } -}; - -export const cartAdd = (item) => ({ - type: CART_ADD, item, -}); - -export const cartRemove = (item) => ({ - type: CART_REMOVE, item, -}); - -export const cartClear = () => ({ - type: CART_CLEAR, -}); diff --git a/Lab5/src/components/input/Select.jsx b/Lab5/src/components/input/Select.jsx deleted file mode 100644 index 03eb53f..0000000 --- a/Lab5/src/components/input/Select.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import PropTypes from 'prop-types'; -import { Form } from 'react-bootstrap'; - -const Select = ({ - values, name, label, value, onChange, className, ...rest -}) => { - return ( - - {label} - - - { - values.map((type) => ) - } - - - ); -}; - -Select.propTypes = { - values: PropTypes.array, - name: PropTypes.string, - label: PropTypes.string, - value: PropTypes.string, - onChange: PropTypes.func, - className: PropTypes.string, -}; - -export default Select;