├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── logo512.png
├── manifest.json
└── index.html
├── src
├── index.js
├── App.test.js
├── App.js
├── components
│ ├── Navbar.js
│ ├── CartContainer.js
│ └── CartItem.js
├── cart-items.js
└── index.css
├── .gitignore
├── package.json
└── README.md
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john-smilga/starter-project-redux-tutorial-cart/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john-smilga/starter-project-redux-tutorial-cart/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john-smilga/starter-project-redux-tutorial-cart/HEAD/public/logo512.png
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import "./index.css";
4 | import App from "./App";
5 |
6 | ReactDOM.render(, document.getElementById("root"));
7 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // components
3 | import Navbar from "./components/Navbar";
4 | import CartContainer from "./components/CartContainer";
5 | // items
6 | import cartItems from "./cart-items";
7 | // redux stuff
8 |
9 | function App() {
10 | // cart setup
11 |
12 | return (
13 |
14 |
15 |
16 |
17 | );
18 | }
19 |
20 | export default App;
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/components/Navbar.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | const Navbar = () => {
3 | return (
4 |
17 | );
18 | };
19 |
20 | export default Navbar;
21 |
--------------------------------------------------------------------------------
/src/cart-items.js:
--------------------------------------------------------------------------------
1 | export default [
2 | {
3 | id: 1,
4 | title: "Samsung Galaxy S7",
5 | price: 599.99,
6 | img:
7 | "https://res.cloudinary.com/diqqf3eq2/image/upload/v1583368215/phone-2_ohtt5s.png",
8 | amount: 1
9 | },
10 | {
11 | id: 2,
12 | title: "google pixel ",
13 | price: 499.99,
14 | img:
15 | "https://res.cloudinary.com/diqqf3eq2/image/upload/v1583371867/phone-1_gvesln.png",
16 | amount: 1
17 | },
18 | {
19 | id: 3,
20 | title: "Xiaomi Redmi Note 2",
21 | price: 699.99,
22 | img:
23 | "https://res.cloudinary.com/diqqf3eq2/image/upload/v1583368224/phone-3_h2s6fo.png",
24 | amount: 1
25 | }
26 | ];
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "scrimba-cart",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.5.0",
8 | "@testing-library/user-event": "^7.2.1",
9 | "react": "^16.13.0",
10 | "react-dom": "^16.13.0",
11 | "react-redux": "^7.2.0",
12 | "react-scripts": "3.4.0",
13 | "redux": "^4.0.5",
14 | "redux-devtools-extension": "^2.13.8"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test",
20 | "eject": "react-scripts eject"
21 | },
22 | "eslintConfig": {
23 | "extends": "react-app"
24 | },
25 | "browserslist": {
26 | "production": [
27 | ">0.2%",
28 | "not dead",
29 | "not op_mini all"
30 | ],
31 | "development": [
32 | "last 1 chrome version",
33 | "last 1 firefox version",
34 | "last 1 safari version"
35 | ]
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/components/CartContainer.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import CartItem from "./CartItem";
3 | const CartContainer = ({ cart = [] }) => {
4 | if (cart.length === 0) {
5 | return (
6 |
7 | {/* cart header */}
8 |
9 | your bag
10 | is currently empty
11 |
12 |
13 | );
14 | }
15 | return (
16 |
17 | {/* cart header */}
18 |
21 | {/* cart items */}
22 |
23 | {cart.map(item => {
24 | return ;
25 | })}
26 |
27 | {/* cart footer */}
28 |
37 |
38 | );
39 | };
40 |
41 | export default CartContainer;
42 |
--------------------------------------------------------------------------------
/src/components/CartItem.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const CartItem = ({ img, title, price, amount }) => {
4 | return (
5 |
6 |

7 |
8 |
{title}
9 | ${price}
10 | {/* remove button */}
11 |
12 |
13 |
14 | {/* increase amount */}
15 |
20 | {/* amount */}
21 |
{amount}
22 | {/* decrease amount */}
23 |
28 |
29 |
30 | );
31 | };
32 |
33 | export default CartItem;
34 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Recording
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `npm start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `npm test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `npm run build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `npm run eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | 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.
35 |
36 | 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.
37 |
38 | 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.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `npm run build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | /*
2 | ===============
3 | Fonts
4 | ===============
5 | */
6 | @import url("https://fonts.googleapis.com/css?family=Catamaran:400,700&display=swap");
7 |
8 | /*
9 | ===============
10 | Variables
11 | ===============
12 | */
13 |
14 | :root {
15 | --clr-primary: #2680c0;
16 | --clr-primary-dark: hsl(205, 100%, 21%);
17 | --clr-primary-light: hsl(205, 84%, 74%);
18 | --clr-grey-1: #102a42;
19 | --clr-grey-5: #617d98;
20 | --clr-grey-10: #f1f5f8;
21 | --clr-white: #fff;
22 | --clr-red-dark: hsl(360, 67%, 44%);
23 | --clr-red-light: hsl(360, 71%, 66%);
24 | --ff-primary: "Catamaran", sans-serif;
25 | --transition: all 0.3s linear;
26 | --spacing: 0.25rem;
27 | --radius: 0.5rem;
28 | --large-screen-width: 1170px;
29 | --small-screen-width: 90vw;
30 | --fixed-width: 50rem;
31 | }
32 | * {
33 | margin: 0;
34 | padding: 0;
35 | box-sizing: border-box;
36 | }
37 | body {
38 | font-family: var(--ff-primary);
39 | background: var(--clr-grey-10);
40 | color: var(--clr-grey-1);
41 | line-height: 1.5;
42 | font-size: 0.875rem;
43 | }
44 | a {
45 | text-decoration: none;
46 | }
47 | img {
48 | width: 100%;
49 | display: block;
50 | }
51 | h1,
52 | h2,
53 | h3,
54 | h4 {
55 | letter-spacing: var(--spacing);
56 | text-transform: capitalize;
57 | line-height: 1.25;
58 | margin-bottom: 0.75rem;
59 | }
60 | h1 {
61 | font-size: 3rem;
62 | }
63 | h2 {
64 | font-size: 2rem;
65 | }
66 | h3 {
67 | font-size: 1.5rem;
68 | }
69 | h4 {
70 | font-size: 0.875rem;
71 | }
72 | p {
73 | margin-bottom: 1.25rem;
74 | }
75 | @media screen and (min-width: 800px) {
76 | h1 {
77 | font-size: 4rem;
78 | }
79 | h2 {
80 | font-size: 2.5rem;
81 | }
82 | h3 {
83 | font-size: 2rem;
84 | }
85 | h4 {
86 | font-size: 1rem;
87 | }
88 | body {
89 | font-size: 1rem;
90 | }
91 | h1,
92 | h2,
93 | h3,
94 | h4 {
95 | line-height: 1;
96 | }
97 | }
98 | /* more global css */
99 |
100 | .btn {
101 | text-transform: uppercase;
102 | background: var(--clr-primary);
103 | color: var(--clr-white);
104 | padding: 0.375rem 0.75rem;
105 | letter-spacing: var(--spacing);
106 | display: inline-block;
107 | font-weight: 700;
108 | transition: var(--transition);
109 | font-size: 0.875rem;
110 | border: none;
111 | cursor: pointer;
112 | box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
113 | }
114 | .btn:hover {
115 | color: var(--clr-primary);
116 | background: var(--clr-primary-light);
117 | }
118 |
119 | /*
120 | ===============
121 | Navbar
122 | ===============
123 | */
124 | nav {
125 | background: var(--clr-primary);
126 | padding: 1.25rem 2rem;
127 | }
128 | .nav-center {
129 | max-width: var(--fixed-width);
130 | width: 100%;
131 | margin: 0 auto;
132 | display: flex;
133 | justify-content: space-between;
134 | align-items: center;
135 | }
136 | nav h3 {
137 | margin-bottom: 0;
138 | color: var(--clr-white);
139 | }
140 | .nav-container {
141 | display: block;
142 | position: relative;
143 | }
144 | nav svg {
145 | width: 2rem;
146 | fill: var(--clr-white);
147 | }
148 | .amount-container {
149 | position: absolute;
150 | top: -0.75rem;
151 | right: -0.75rem;
152 | width: 1.75rem;
153 | height: 1.75rem;
154 | border-radius: 50%;
155 | background: var(--clr-primary-light);
156 | display: flex;
157 | align-items: center;
158 | justify-content: center;
159 | }
160 | .total-amount {
161 | color: var(--clr-white);
162 | margin-bottom: 0;
163 | font-size: 1.25rem;
164 | }
165 | /*
166 | ===============
167 | Cart
168 | ===============
169 | */
170 | .cart {
171 | min-height: calc(100vh - 80px);
172 | width: 90vw;
173 | margin: 0 auto;
174 | padding: 2.5rem 0;
175 | max-width: var(--fixed-width);
176 | }
177 | .cart h2 {
178 | text-transform: uppercase;
179 | text-align: center;
180 | margin-bottom: 1.25rem;
181 | }
182 | .empty-cart {
183 | text-transform: lowercase;
184 | color: var(--clr-grey-5);
185 | margin-top: 1rem;
186 | text-align: center;
187 | }
188 | .cart footer {
189 | margin-top: 4rem;
190 | text-align: center;
191 | }
192 | .cart-total h4 {
193 | text-transform: capitalize;
194 | display: flex;
195 | justify-content: space-between;
196 | margin-top: 1rem;
197 | }
198 | .clear-btn {
199 | background: transparent;
200 | padding: 0.5rem 1rem;
201 | color: var(--clr-red-dark);
202 | border: 1px solid var(--clr-red-dark);
203 | margin-top: 2.25rem;
204 | }
205 | .clear-btn:hover {
206 | background: var(--clr-red-light);
207 | color: var(--clr-red-dark);
208 | border-color: var(--clr-red-light);
209 | }
210 | /*
211 | ===============
212 | Cart Item
213 | ===============
214 | */
215 | .cart-item {
216 | display: grid;
217 | align-items: center;
218 | grid-template-columns: auto 1fr auto;
219 | grid-column-gap: 1.5rem;
220 | margin: 1.5rem 0;
221 | }
222 | .cart-item img {
223 | width: 5rem;
224 | height: 5rem;
225 | object-fit: cover;
226 | }
227 | .cart-item h4 {
228 | margin-bottom: 0.5rem;
229 | font-weight: 500;
230 | letter-spacing: 2px;
231 | }
232 | .item-price {
233 | color: var(--clr-grey-5);
234 | }
235 | .remove-btn {
236 | color: var(--clr-primary);
237 | letter-spacing: var(--spacing);
238 | cursor: pointer;
239 | font-size: 0.85rem;
240 | background: transparent;
241 | border: none;
242 | margin-top: 0.375rem;
243 | transition: var(--transition);
244 | }
245 | .remove-btn:hover {
246 | color: var(--clr-primary-light);
247 | }
248 | .amount-btn {
249 | width: 1.5rem;
250 | background: transparent;
251 | border: none;
252 | cursor: pointer;
253 | }
254 | .amount-btn svg {
255 | fill: var(--clr-primary);
256 | }
257 | .amount-btn:hover svg {
258 | fill: var(--clr-primary-light);
259 | }
260 | .amount {
261 | text-align: center;
262 | margin-bottom: 0;
263 | font-size: 1.25rem;
264 | line-height: 1;
265 | }
266 |
--------------------------------------------------------------------------------