├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── cart.gif ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── components ├── Cards.js ├── CardsData.js ├── CardsDetails.js ├── Header.js └── style.css ├── index.css ├── index.js ├── logo.svg ├── redux ├── actions │ └── action.js └── reducers │ ├── main.js │ └── reducer.js ├── reportWebVitals.js ├── setupTests.js └── store.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "addtocart", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.8.2", 7 | "@emotion/styled": "^11.8.1", 8 | "@mui/icons-material": "^5.5.1", 9 | "@mui/material": "^5.5.1", 10 | "@testing-library/jest-dom": "^5.16.2", 11 | "@testing-library/react": "^12.1.4", 12 | "@testing-library/user-event": "^13.5.0", 13 | "bootstrap": "^5.1.3", 14 | "react": "^17.0.2", 15 | "react-bootstrap": "^2.2.1", 16 | "react-dom": "^17.0.2", 17 | "react-redux": "^7.2.6", 18 | "react-router-dom": "^6.2.2", 19 | "react-scripts": "5.0.0", 20 | "redux": "^4.1.2", 21 | "web-vitals": "^2.1.4" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /public/cart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh17112000/react_redux_cart_youtube/2466e2770af0f50814b2fe9c26a45603118a9ad5/public/cart.gif -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh17112000/react_redux_cart_youtube/2466e2770af0f50814b2fe9c26a45603118a9ad5/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 19 | 28 | React App 29 | 30 | 31 | 32 |
33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh17112000/react_redux_cart_youtube/2466e2770af0f50814b2fe9c26a45603118a9ad5/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harsh17112000/react_redux_cart_youtube/2466e2770af0f50814b2fe9c26a45603118a9ad5/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | import 'bootstrap/dist/css/bootstrap.min.css'; 4 | import Header from './components/Header'; 5 | import CardsDetails from './components/CardsDetails'; 6 | import Cards from './components/Cards'; 7 | import {Routes,Route} from "react-router-dom"; 8 | 9 | function App() { 10 | return ( 11 | <> 12 |
13 | 14 | } /> 15 | } /> 16 | 17 | 18 | ); 19 | } 20 | 21 | export default App; 22 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/components/Cards.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | import Card from 'react-bootstrap/Card' 3 | import Button from 'react-bootstrap/Button' 4 | import Cardsdata from './CardsData' 5 | import "./style.css"; 6 | import { useDispatch } from 'react-redux'; 7 | import { ADD } from '../redux/actions/action'; 8 | 9 | const Cards = () => { 10 | 11 | const [data, setData] = useState(Cardsdata); 12 | // console.log(data); 13 | 14 | 15 | const dispatch = useDispatch(); 16 | 17 | 18 | const send = (e)=>{ 19 | // console.log(e); 20 | dispatch(ADD(e)); 21 | } 22 | 23 | return ( 24 |
25 |

Add to Cart Projects

26 | 27 |
28 | { 29 | data.map((element, id) => { 30 | return ( 31 | <> 32 | 33 | 34 | 35 | {element.rname} 36 | 37 | Price : ₹ {element.price} 38 | 39 |
40 | 43 |
44 | 45 |
46 |
47 | 48 | ) 49 | }) 50 | } 51 | 52 |
53 |
54 | ) 55 | } 56 | 57 | export default Cards -------------------------------------------------------------------------------- /src/components/CardsData.js: -------------------------------------------------------------------------------- 1 | const Cardsdata = [ 2 | { 3 | id: 1, 4 | rname: "Massala Theoryy", 5 | imgdata: "https://b.zmtcdn.com/data/pictures/9/18857339/8f53919f1175c08cf0f0371b73704f9b_o2_featured_v2.jpg?output-format=webp", 6 | address: "North Indian, Biryani, Mughlai", 7 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 8 | somedata: " 1175 + order placed from here recently", 9 | price: 350, 10 | rating: "3.8", 11 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 12 | qnty:0 13 | }, 14 | { 15 | id: 2, 16 | rname: "Jugaadi Adda", 17 | imgdata: "https://b.zmtcdn.com/data/pictures/chains/5/19295245/089cbcf1d3307542c72f77272556b28b_o2_featured_v2.jpg?output-format=webp", 18 | address: "Street Food", 19 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 20 | somedata: " 2525 + order placed from here recently", 21 | price: 25, 22 | rating: "3.9", 23 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 24 | qnty:0 25 | }, 26 | { 27 | id: 3, 28 | rname: "La Milano Pizzeria", 29 | imgdata: "https://b.zmtcdn.com/data/pictures/chains/1/19708611/10f90d4a69678d98662514d173b29665_o2_featured_v2.jpg", 30 | address: "Pizza, Fast Food, Pasta", 31 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 32 | somedata: " 650 + order placed from here recently", 33 | price: 70, 34 | rating: "4.2", 35 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 36 | qnty:0 37 | }, 38 | { 39 | id: 4, 40 | rname: "Momoman", 41 | imgdata: "https://b.zmtcdn.com/data/pictures/chains/1/113401/59f29399060caefcc575d59dc9402ce8_o2_featured_v2.jpg", 42 | address: "Momos", 43 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 44 | somedata: " 300 + order placed from here recently", 45 | price: 70, 46 | rating: "3.8", 47 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 48 | qnty:0 49 | }, 50 | { 51 | id: 5, 52 | rname: "Jassi De Parathe", 53 | imgdata: "https://b.zmtcdn.com/data/pictures/chains/5/110225/3978e28854b7496dbef9496546734811_o2_featured_v2.jpg", 54 | address: "North Indian", 55 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 56 | somedata: "1050 + order placed from here recently", 57 | price: 210, 58 | rating: "4.0", 59 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 60 | qnty:0 61 | }, 62 | { 63 | id: 6, 64 | rname: "Anjoy Latenight Meals", 65 | imgdata: "https://b.zmtcdn.com/data/pictures/5/113895/3c06f6fbb8f667a2537dfdb6f060dc8b_o2_featured_v2.jpg", 66 | address: "Wraps FastFood, Chines", 67 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 68 | somedata: " 1100 + order placed from here recently", 69 | price: 100, 70 | rating: "3.8", 71 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 72 | qnty:0 73 | }, 74 | { 75 | id: 7, 76 | rname: "Hocco Eatery", 77 | imgdata: "https://b.zmtcdn.com/data/pictures/chains/5/110155/811c01a5430d50d3260f77917da99e12_o2_featured_v2.jpg", 78 | address: "North Indian, Fast Food", 79 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 80 | somedata: "500 + order placed from here recently", 81 | price: 300, 82 | rating: "3.8", 83 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 84 | qnty:0 85 | }, 86 | { 87 | id: 8, 88 | rname: "Chai Wai", 89 | imgdata: "https://b.zmtcdn.com/data/pictures/3/18514413/0a17b72e9fec52a3ca736f4c2ea3646f_o2_featured_v2.jpg", 90 | address: "Tea, Coffee, Shake, Beverages", 91 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 92 | somedata: "500 + order placed from here recently", 93 | price: 100, 94 | rating: "3.2", 95 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 96 | qnty:0 97 | }, 98 | { 99 | id: 9, 100 | rname: "HL Frankie", 101 | imgdata: "https://b.zmtcdn.com/data/pictures/7/19639627/94c0a4cf15c02d3982d154e2c5dd8cbb_o2_featured_v2.jpg", 102 | address: "Burger, Sandwich, Fast Food", 103 | delimg: "https://b.zmtcdn.com/data/o2_assets/0b07ef18234c6fdf9365ad1c274ae0631612687510.png?output-format=webp", 104 | somedata: "2525 + order placed from here recently", 105 | price: 100, 106 | rating: "3.8", 107 | arrimg: "https://b.zmtcdn.com/data/o2_assets/4bf016f32f05d26242cea342f30d47a31595763089.png?output-format=webp", 108 | qnty:0 109 | }, 110 | ]; 111 | 112 | export default Cardsdata; -------------------------------------------------------------------------------- /src/components/CardsDetails.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import Table from 'react-bootstrap/Table' 3 | import { useNavigate, useParams } from 'react-router-dom' 4 | import { useDispatch, useSelector } from 'react-redux' 5 | import { DLT,ADD,REMOVE } from '../redux/actions/action' 6 | 7 | 8 | const CardsDetails = () => { 9 | 10 | const [data,setData] = useState([]); 11 | // console.log(data); 12 | 13 | const {id} = useParams(); 14 | // console.log(id); 15 | 16 | const history = useNavigate(); 17 | 18 | const dispatch = useDispatch(); 19 | 20 | 21 | const getdata = useSelector((state)=> state.cartreducer.carts); 22 | // console.log(getdata); 23 | 24 | 25 | const compare = ()=>{ 26 | let comparedata = getdata.filter((e)=>{ 27 | return e.id == id 28 | }); 29 | setData(comparedata); 30 | } 31 | 32 | // add data 33 | 34 | 35 | const send = (e)=>{ 36 | // console.log(e); 37 | dispatch(ADD(e)); 38 | } 39 | 40 | const dlt = (id)=>{ 41 | dispatch(DLT(id)); 42 | history("/"); 43 | } 44 | 45 | // remove one 46 | const remove = (item)=>{ 47 | dispatch(REMOVE(item)) 48 | } 49 | 50 | 51 | useEffect(()=>{ 52 | compare(); 53 | },[id]) 54 | 55 | return ( 56 | <> 57 |
58 |

Iteams Details Page 59 |

60 | 61 |
62 |
63 | { 64 | data.map((ele)=>{ 65 | return ( 66 | <> 67 |
68 | 69 |
70 | 71 |
72 | 73 | 74 | 87 | 92 | 93 |
75 |

Restaurant : {ele.rname}

76 |

Price : ₹{ele.price}

77 |

Dishes : {ele.address}

78 |

Total :₹ {ele.price * ele.qnty}

79 |
80 | dlt(ele.id) : ()=>remove(ele)}>- 81 | {ele.qnty} 82 | send(ele)}>+ 83 | 84 |
85 | 86 |
88 |

Rating : {ele.rating} ★

89 |

Order Review : {ele.somedata}

90 |

Remove : dlt(ele.id)} style={{color:"red",fontSize:20,cursor:"pointer"}}>

91 |
94 |
95 | 96 | 97 | ) 98 | }) 99 | } 100 |
101 |
102 |
103 | 104 | ) 105 | } 106 | 107 | export default CardsDetails -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import Navbar from 'react-bootstrap/Navbar' 3 | import Container from 'react-bootstrap/Container' 4 | import Badge from '@mui/material/Badge'; 5 | import Nav from 'react-bootstrap/Nav' 6 | import Menu from '@mui/material/Menu'; 7 | import MenuItem from '@mui/material/MenuItem'; 8 | import { NavLink } from 'react-router-dom'; 9 | import { useDispatch, useSelector } from 'react-redux'; 10 | import Table from 'react-bootstrap/esm/Table'; 11 | import { DLT } from '../redux/actions/action'; 12 | 13 | const Header = () => { 14 | 15 | const [price,setPrice] = useState(0); 16 | // console.log(price); 17 | 18 | const getdata = useSelector((state)=> state.cartreducer.carts); 19 | // console.log(getdata); 20 | 21 | const dispatch = useDispatch(); 22 | 23 | const [anchorEl, setAnchorEl] = useState(null); 24 | const open = Boolean(anchorEl); 25 | const handleClick = (event) => { 26 | setAnchorEl(event.currentTarget); 27 | }; 28 | const handleClose = () => { 29 | setAnchorEl(null); 30 | }; 31 | 32 | 33 | const dlt = (id)=>{ 34 | dispatch(DLT(id)) 35 | } 36 | 37 | 38 | const total = ()=>{ 39 | let price = 0; 40 | getdata.map((ele,k)=>{ 41 | price = ele.price * ele.qnty + price 42 | }); 43 | setPrice(price); 44 | }; 45 | 46 | useEffect(()=>{ 47 | total(); 48 | },[total]) 49 | 50 | return ( 51 | <> 52 | 53 | 54 | Add to Cart 55 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 81 | 82 | { 83 | getdata.length ? 84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | { 94 | getdata.map((e)=>{ 95 | return ( 96 | <> 97 | 98 | 103 | 111 | 112 | 115 | 116 | 117 | ) 118 | }) 119 | } 120 |

Total :₹ {price}

121 | 122 |
PhotoRestaurant Name
99 | 100 | 101 | 102 | 104 |

{e.rname}

105 |

Price : ₹{e.price}

106 |

Quantity : {e.qnty}

107 |

dlt(e.id)}> 108 | 109 |

110 |
dlt(e.id)}> 113 | 114 |
123 |
: 124 | 125 |
126 | 129 |

Your carts is empty

130 | 131 |
132 | } 133 | 134 |
135 |
136 | 137 | ) 138 | } 139 | 140 | export default Header -------------------------------------------------------------------------------- /src/components/style.css: -------------------------------------------------------------------------------- 1 | .card_style{ 2 | cursor: pointer; 3 | transition: .3s; 4 | } 5 | 6 | .smalltrash{ 7 | display: none; 8 | } 9 | 10 | 11 | .card_style:hover{ 12 | box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.082); 13 | } 14 | 15 | .iteamsdetails{ 16 | max-width: 800px; 17 | margin: auto; 18 | display: flex; 19 | justify-content: space-between; 20 | align-items: center; 21 | box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.082); 22 | } 23 | .items_img{ 24 | flex: .4; 25 | } 26 | .items_img img{ 27 | width: 20rem; 28 | border-radius: 5px; 29 | } 30 | 31 | .details{ 32 | flex: .5; 33 | }; 34 | 35 | .rating{ 36 | background-color: green; 37 | } 38 | 39 | @media (max-width:772px){ 40 | .iteamsdetails{ 41 | flex-direction: column; 42 | align-items: center; 43 | justify-content: center; 44 | } 45 | } 46 | 47 | @media (max-width:450px){ 48 | .smalltrash{ 49 | display: block; 50 | } 51 | .largetrash{ 52 | display:none; 53 | } 54 | .emptycart_img{ 55 | margin-right: 50px; 56 | } 57 | .smallclose{ 58 | display: none; 59 | } 60 | 61 | /* individual iteams details */ 62 | 63 | .items_img img{ 64 | width: 16rem; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import store from './store'; 6 | import { Provider } from 'react-redux'; 7 | import { BrowserRouter } from "react-router-dom"; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | 15 | 16 | , 17 | document.getElementById('root') 18 | ); 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/redux/actions/action.js: -------------------------------------------------------------------------------- 1 | export const ADD = (item) => { 2 | return { 3 | type: "ADD_CART", 4 | payload: item 5 | } 6 | } 7 | 8 | // remove iteams 9 | export const DLT = (id) => { 10 | return { 11 | type: "RMV_CART", 12 | payload: id 13 | } 14 | } 15 | 16 | // remove individual iteam 17 | 18 | export const REMOVE = (iteam) => { 19 | return { 20 | type: "RMV_ONE", 21 | payload: iteam 22 | } 23 | } -------------------------------------------------------------------------------- /src/redux/reducers/main.js: -------------------------------------------------------------------------------- 1 | import {combineReducers} from "redux"; 2 | import { cartreducer } from "./reducer"; 3 | 4 | 5 | const rootred = combineReducers({ 6 | cartreducer 7 | }); 8 | 9 | 10 | export default rootred -------------------------------------------------------------------------------- /src/redux/reducers/reducer.js: -------------------------------------------------------------------------------- 1 | const INIT_STATE = { 2 | carts: [] 3 | }; 4 | 5 | 6 | export const cartreducer = (state = INIT_STATE, action) => { 7 | switch (action.type) { 8 | case "ADD_CART": 9 | 10 | const IteamIndex = state.carts.findIndex((iteam)=> iteam.id === action.payload.id); 11 | 12 | if(IteamIndex >= 0){ 13 | state.carts[IteamIndex].qnty +=1 14 | return { 15 | ...state, 16 | carts:[...state.carts] 17 | } 18 | }else{ 19 | const temp = {...action.payload,qnty:1} 20 | return { 21 | ...state, 22 | carts: [...state.carts, temp] 23 | } 24 | } 25 | 26 | 27 | 28 | case "RMV_CART": 29 | const data = state.carts.filter((el)=>el.id !== action.payload); 30 | // console.log(data); 31 | 32 | return { 33 | ...state, 34 | carts:data 35 | } 36 | 37 | case "RMV_ONE": 38 | const IteamIndex_dec = state.carts.findIndex((iteam)=> iteam.id === action.payload.id); 39 | 40 | if(state.carts[IteamIndex_dec].qnty >= 1){ 41 | const dltiteams = state.carts[IteamIndex_dec].qnty -= 1 42 | console.log([...state.carts,dltiteams]); 43 | 44 | return { 45 | ...state, 46 | carts:[...state.carts] 47 | } 48 | }else if(state.carts[IteamIndex_dec].qnty === 1 ){ 49 | const data = state.carts.filter((el)=>el.id !== action.payload); 50 | 51 | return { 52 | ...state, 53 | carts:data 54 | } 55 | } 56 | 57 | default: 58 | return state 59 | } 60 | } -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/store.js: -------------------------------------------------------------------------------- 1 | import { createStore } from "redux"; 2 | import rootred from "./redux/reducers/main"; 3 | 4 | 5 | const store = createStore( 6 | rootred 7 | ); 8 | 9 | 10 | export default store; --------------------------------------------------------------------------------