├── .firebase
└── hosting.YnVpbGQ.cache
├── .firebaserc
├── .gitignore
├── README.md
├── firebase.json
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
├── src
├── App.css
├── App.js
├── App.test.js
├── Cart.js
├── CartItem.js
├── CartItems.js
├── CartTotal.js
├── Header.js
├── Home.js
├── Login.js
├── Product.js
├── firebase.js
├── index.css
├── index.js
├── logo.svg
├── reportWebVitals.js
└── setupTests.js
└── yarn.lock
/.firebase/hosting.YnVpbGQ.cache:
--------------------------------------------------------------------------------
1 | asset-manifest.json,1616876459355,3cedea2ad24f318c2a04e8dcef80dffddc42786c53f47f71dc307a1c1f0166e7
2 | index.html,1616876459355,2f19febfeb05886bb5c4f30a1d0ec08d88cf38c369c57397b531d121039175de
3 | favicon.ico,1616876432762,b72f7455f00e4e58792d2bca892abb068e2213838c0316d6b7a0d6d16acd1955
4 | static/css/main.bd7f302f.chunk.css.map,1616876459368,04bddecb033e6a9f61cc542ef8c2397c841e348d557a54fc0db1ec8cd10cdaff
5 | static/css/main.bd7f302f.chunk.css,1616876459356,9e071d362c8feacad63ce781ae893fef82a0e26d9dc68b73a64279daa489ed64
6 | logo192.png,1616876432763,caff018b7f1e8fd481eb1c50d75b0ef236bcd5078b1d15c8bb348453fee30293
7 | logo512.png,1616876432763,191fc21360b4ccfb1cda11a1efb97f489ed22672ca83f4064316802bbfdd750e
8 | manifest.json,1616876432764,341d52628782f8ac9290bbfc43298afccb47b7cbfcee146ae30cf0f46bc30900
9 | static/js/2.2481bd68.chunk.js.LICENSE.txt,1616876459367,2229a48f297ad41772f09041efcede8dd16c8708477b3af5042f140321999c8e
10 | static/js/3.afd62009.chunk.js,1616876459368,0836e074b3992a17c1d3adb1afc8504472f07f5aa536f272391ea42be6c23553
11 | static/js/runtime-main.bd3ac1e9.js,1616876459367,6f91e6730a967cde9207aaf128e95c37b66182f4a52ad0c1ae88667d244c8071
12 | static/js/main.94520b71.chunk.js,1616876459367,46f2cd10d379b3522577f1b6743d8b405029fff91bbb36fd84001fe089a2178e
13 | static/js/3.afd62009.chunk.js.map,1616876459368,3b28f4f5e461c28bec63703ac58a358222c475e392acd6e40329a911c7689617
14 | robots.txt,1616876432764,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
15 | static/js/runtime-main.bd3ac1e9.js.map,1616876459367,2d108bc596809bb94ceb39cf79fd4034aace3aea3bb8c4aee8ffcafa7bdfdc2b
16 | static/js/main.94520b71.chunk.js.map,1616876459369,8a0902143f3024777a172b1ccabf94d8e4d14567d9a50ea2e6c63af03837612c
17 | static/js/2.2481bd68.chunk.js,1616876459367,3fbf3ec604b79e3fdff440a88d88a53acebc378026a35924a6af53ef18aa33c8
18 | static/js/2.2481bd68.chunk.js.map,1616876459369,7f11917b9aa9effc10ec89b6ae4d799d118a5b06b8182b935a41a401e3369eeb
19 |
--------------------------------------------------------------------------------
/.firebaserc:
--------------------------------------------------------------------------------
1 | {
2 | "projects": {
3 | "default": "clone-mar21"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.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 | ### `yarn start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13 |
14 | The page will reload if you make edits.\
15 | You will also see any lint errors in the console.
16 |
17 | ### `yarn 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 | ### `yarn 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 | ### `yarn 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 | ### `yarn 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 |
--------------------------------------------------------------------------------
/firebase.json:
--------------------------------------------------------------------------------
1 | {
2 | "hosting": {
3 | "public": "build",
4 | "ignore": [
5 | "firebase.json",
6 | "**/.*",
7 | "**/node_modules/**"
8 | ],
9 | "rewrites": [
10 | {
11 | "source": "**",
12 | "destination": "/index.html"
13 | }
14 | ]
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "amazon-clone-challenge",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@material-ui/core": "^4.11.3",
7 | "@material-ui/icons": "^4.11.2",
8 | "@testing-library/jest-dom": "^5.11.4",
9 | "@testing-library/react": "^11.1.0",
10 | "@testing-library/user-event": "^12.1.10",
11 | "firebase": "^8.3.1",
12 | "firebase-tools": "^9.8.0",
13 | "react": "^17.0.2",
14 | "react-dom": "^17.0.2",
15 | "react-number-format": "^4.5.1",
16 | "react-router-dom": "^5.2.0",
17 | "react-scripts": "4.0.3",
18 | "styled-components": "^5.2.1",
19 | "web-vitals": "^1.0.1"
20 | },
21 | "scripts": {
22 | "start": "react-scripts start",
23 | "build": "react-scripts build",
24 | "test": "react-scripts test",
25 | "eject": "react-scripts eject"
26 | },
27 | "eslintConfig": {
28 | "extends": [
29 | "react-app",
30 | "react-app/jest"
31 | ]
32 | },
33 | "browserslist": {
34 | "production": [
35 | ">0.2%",
36 | "not dead",
37 | "not op_mini all"
38 | ],
39 | "development": [
40 | "last 1 chrome version",
41 | "last 1 firefox version",
42 | "last 1 safari version"
43 | ]
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CleverProgrammers/react-challenge-march21-amazon-clone/46b9c01a2b12901192076a165bc3c6761202ac95/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CleverProgrammers/react-challenge-march21-amazon-clone/46b9c01a2b12901192076a165bc3c6761202ac95/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CleverProgrammers/react-challenge-march21-amazon-clone/46b9c01a2b12901192076a165bc3c6761202ac95/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 | * {
2 | margin: 0;
3 | }
4 |
5 | body {
6 | background-color: #EAEDED;
7 | }
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react'
2 | import './App.css';
3 | import Header from './Header'
4 | import Cart from './Cart'
5 | import Home from './Home'
6 | import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"
7 | import styled from 'styled-components'
8 | import { db, auth } from './firebase'
9 | import Login from './Login'
10 |
11 | function App() {
12 | const [user, setUser] = useState(JSON.parse(localStorage.getItem('user')));
13 | const [cartItems, setCartItems] = useState([]);
14 |
15 | const getCartItems = () => {
16 | db.collection('cartItems').onSnapshot((snapshot) => {
17 | const tempItems = snapshot.docs.map((doc) => ({
18 | id: doc.id,
19 | product: doc.data()
20 | }))
21 |
22 | setCartItems(tempItems);
23 | })
24 | }
25 |
26 | const signOut = () => {
27 | auth.signOut().then(()=>{
28 | localStorage.removeItem('user')
29 | setUser(null)
30 | })
31 | }
32 |
33 | useEffect(() => {
34 | getCartItems();
35 | }, [])
36 |
37 |
38 | return (
39 |
40 | {
41 | !user ? (
42 |
43 | ) : (
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | )
63 | }
64 |
65 | );
66 | }
67 |
68 | export default App;
69 |
70 | const Container = styled.div`
71 | background-color: #EAEDED;
72 | `
73 |
--------------------------------------------------------------------------------
/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/Cart.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import CartItems from './CartItems'
4 | import CartTotal from './CartTotal'
5 |
6 | function Cart({ cartItems }) {
7 |
8 | const getTotalPrice = () => {
9 | let total = 0;
10 | cartItems.forEach((item)=>{
11 | total += (item.product.price * item.product.quantity)
12 | })
13 | return total;
14 | }
15 |
16 | const getCount = () => {
17 | let count = 0;
18 | // Loop through all cart items
19 | cartItems.forEach((item) => {
20 | // add the quantity of the cart item to tota;
21 | count += item.product.quantity;
22 | })
23 |
24 | return count;
25 | }
26 |
27 | return (
28 |
29 |
30 |
31 |
32 | )
33 | }
34 |
35 | export default Cart
36 |
37 | const Container = styled.div`
38 | display: flex;
39 | //TRouBLe
40 | padding: 14px 18px 0 18px;
41 | align-items: flex-start;
42 | `
43 |
44 |
--------------------------------------------------------------------------------
/src/CartItem.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { db } from './firebase'
4 |
5 | const CartItem = ({ id, item }) => {
6 |
7 | const deleteItem = (e) => {
8 | e.preventDefault()
9 | db.collection('cartItems').doc(id).delete();
10 | }
11 |
12 |
13 | let options = []
14 |
15 | for (let i = 1; i < Math.max(item.quantity + 1, 20); i++) {
16 | options.push()
17 | }
18 |
19 | const changeQuantity = (newQuantity) => {
20 | db.collection('cartItems').doc(id).update({
21 | quantity: parseInt(newQuantity)
22 | })
23 | }
24 |
25 | return (
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | {item.name}
34 |
35 |
36 |
37 |
43 |
44 |
47 | Delete
48 |
49 |
50 |
51 |
52 | ${item.price}
53 |
54 |
55 | )
56 | }
57 |
58 | export default CartItem
59 |
60 |
61 | const Container = styled.div`
62 | padding-top: 12px;
63 | padding-bottom: 12px;
64 | display: flex;
65 | border-bottom: 1px solid #DDD;
66 | `
67 |
68 | const ImageContainer = styled.div`
69 | width: 180px;
70 | height: 180px;
71 | flex-shrink: 0;
72 | flex-grow: 0;
73 | margin-right: 16px;
74 | img{
75 | object-fit: contain;
76 | height: 100%;
77 | width: 100%;
78 | }
79 | `
80 | const CartItemInfo = styled.div`
81 | flex-grow: 1;
82 | `
83 |
84 | const CartItemInfoTop = styled.div`
85 | color: #007185;
86 | h2 {
87 | font-size: 18px;
88 | }
89 | `
90 |
91 | const CartItemInfoBottom = styled.div`
92 | display: flex;
93 | margin-top: 4px;
94 | align-items: center;
95 | `
96 |
97 | const CartItemQuantityContainer = styled.div`
98 | select {
99 | border-radius: 7px;
100 | background-color: #F0F2F2;
101 | padding: 8px;
102 | box-shadow: 0 2px 5px rgba(15,17,17,.15);
103 |
104 | :focus {
105 | outline: none;
106 | }
107 | }
108 | `
109 |
110 | const CartItemDeleteContainer = styled.div`
111 | color: #007185;
112 | margin-left: 16px;
113 | cursor: pointer;
114 | `
115 |
116 | const CartItemPrice = styled.div`
117 | font-size: 18px;
118 | font-weight: 700;
119 | margin-left: 16px;
120 | `
--------------------------------------------------------------------------------
/src/CartItems.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import CartItem from './CartItem'
4 |
5 | function CartItems({ cartItems }) {
6 | return (
7 |
8 | Shopping Cart
9 |
10 |
11 | {
12 | cartItems.map((item)=>(
13 |
17 | ))
18 | }
19 |
20 |
21 | )
22 | }
23 |
24 | export default CartItems
25 |
26 | const Container = styled.div`
27 | flex: 0.8;
28 | padding: 20px;
29 | margin-right: 18px;
30 | background-color: white;
31 | `
32 |
33 | const Title = styled.h1`
34 | margin-bottom: 8px;
35 | `
36 | const ItemsContainer = styled.div`
37 | `
--------------------------------------------------------------------------------
/src/CartTotal.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import NumberFormat from 'react-number-format';
4 |
5 | function CartTotal({ getTotalPrice, getCount }) {
6 |
7 | return (
8 |
9 | Subtotal ({getCount()} items):
10 |
11 |
12 | Proceed to checkout
13 |
14 | )
15 | }
16 |
17 | export default CartTotal
18 |
19 | const Container = styled.div`
20 | flex: 0.3;
21 | padding: 20px;
22 | background-color: white;
23 | `
24 | const Subtotal = styled.h2`
25 | margin-bottom: 16px;
26 | `
27 |
28 | const CheckoutButton = styled.button`
29 | background-color: #f0c14b;
30 | width: 100%;
31 | // vertical - horizontal
32 | padding: 4px 8px;
33 | border: 2px solid #a88734;
34 | border-radius: 4px;
35 | cursor: pointer;
36 | font-size: 16px;
37 | :hover {
38 | background: #ddb347;
39 | }
40 | `
--------------------------------------------------------------------------------
/src/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import SearchIcon from '@material-ui/icons/Search';
4 | import ShoppingBasketIcon from '@material-ui/icons/ShoppingBasket';
5 | import LocationOnIcon from '@material-ui/icons/LocationOn';
6 | import {
7 | Link
8 | } from "react-router-dom";
9 |
10 | function Header({ cartItems, user, signOut }) {
11 |
12 | const getCount = () => {
13 | let count = 0;
14 | // Loop through all cart items
15 | cartItems.forEach((item) => {
16 | // add the quantity of the cart item to tota;
17 | count += item.product.quantity;
18 | })
19 |
20 | return count;
21 | }
22 |
23 |
24 |
25 |
26 | return (
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Hello
38 | Select Your Address
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Hello, {user.name}
54 | Account & Lists
55 |
56 |
57 |
58 | Returns
59 | & Orders
60 |
61 |
62 |
63 |
64 |
65 |
66 | {getCount()}
67 |
68 |
69 |
70 |
71 |
72 |
73 | )
74 | }
75 |
76 | export default Header
77 |
78 | const Container = styled.div`
79 | height: 60px;
80 | background-color: #0F1111;
81 | display: flex;
82 | align-items: center;
83 | justify-content: space-between;
84 | color: white;
85 | `
86 |
87 | const HeaderLogo = styled.div`
88 | img {
89 | width: 100px;
90 | margin-left: 11px;
91 | }
92 | `
93 |
94 | const HeaderOptionAddress = styled.div`
95 | padding-left: 9px;
96 | display: flex;
97 | align-items: center;
98 |
99 | `
100 |
101 | const OptionLineOne = styled.div`
102 |
103 | `
104 |
105 | const OptionLineTwo = styled.div`
106 | font-weight: 700;
107 | `
108 |
109 | const HeaderSearch = styled.div`
110 | display: flex;
111 | flex-grow: 1;
112 | height: 40px;
113 | border-radius: 4px;
114 | overflow: hidden;
115 | margin-left: 4px;
116 | background-color: white;
117 | :focus-within {
118 | box-shadow: 0 0 0 3px #F90;
119 | }
120 | `
121 |
122 |
123 | const HeaderSearchInput = styled.input`
124 | flex-grow: 1;
125 | border: 0;
126 | :focus {
127 | outline: none;
128 | }
129 | `
130 |
131 | const HeaderSearchIconContainer = styled.div`
132 | background-color: #febd69;
133 | width: 45px;
134 | color: black;
135 | display: flex;
136 | justify-content: center;
137 | align-items: center;
138 |
139 | `
140 |
141 | const HeaderNavItems = styled.div`
142 | display: flex;
143 |
144 | `
145 |
146 | const HeaderOption = styled.div`
147 | // TRouBLe
148 | padding: 10px 9px 10px 9px;
149 | cursor: pointer;
150 | `
151 |
152 | const HeaderOptionCart = styled.div`
153 | display: flex;
154 | a {
155 | display: flex;
156 | align-items: center;
157 | padding-right: 9px;
158 | color: white;
159 | text-decoration: none;
160 | }
161 | `
162 |
163 | const CartCount = styled.div`
164 | padding-left: 4px;
165 | font-weight: 700;
166 | color: #f08804;
167 |
168 | `
--------------------------------------------------------------------------------
/src/Home.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import styled from 'styled-components'
3 | import Product from './Product';
4 | import { db } from './firebase'
5 |
6 | function Home() {
7 | const [products, setProducts] = useState([])
8 |
9 | const getProducts = () => {
10 | db.collection('products').onSnapshot((snapshot) => {
11 | let tempProducts = []
12 | tempProducts = snapshot.docs.map((doc) => (
13 | {
14 | id: doc.id,
15 | product: doc.data()
16 | }
17 | ));
18 | setProducts(tempProducts);
19 | })
20 | }
21 |
22 | useEffect(()=>{
23 | console.log("Call products");
24 | getProducts()
25 | }, [])
26 |
27 |
28 | return (
29 |
30 |
31 |
32 |
33 |
34 | {
35 | products.map((data)=>(
36 |
43 | ))
44 | }
45 |
46 |
47 | )
48 | }
49 |
50 | export default Home
51 |
52 | const Container = styled.div`
53 | max-width: 1500px;
54 | margin: 0 auto;
55 | `
56 |
57 | const Banner = styled.div`
58 | background-image: url('https://i.imgur.com/SYHeuYM.jpg');
59 | min-height: 600px;
60 | background-position: center;
61 | background-size: cover;
62 | z-index: 1;
63 | mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
64 | `
65 |
66 | const Content = styled.div`
67 | padding-left: 10px;
68 | padding-right: 10px;
69 | margin-top: -350px;
70 | display: flex;
71 | `
72 |
--------------------------------------------------------------------------------
/src/Login.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { auth, provider } from './firebase'
4 |
5 | function Login({ setUser }) {
6 |
7 | const signIn = () => {
8 | auth.signInWithPopup(provider).then((result)=>{
9 | let user = result.user;
10 | let newUser = {
11 | name: user.displayName,
12 | email: user.email,
13 | photo: user.photoURL
14 | }
15 | localStorage.setItem('user', JSON.stringify(newUser))
16 | setUser(newUser);
17 | }).catch((error)=>{
18 | alert(error.message);
19 | })
20 | }
21 |
22 | return (
23 |
24 |
25 |
26 | Sign into Amazon
27 |
30 | Sign in with Google
31 |
32 |
33 |
34 | )
35 | }
36 |
37 | export default Login
38 |
39 | const Container = styled.div`
40 | width: 100%;
41 | height: 100vh;
42 | background-color: #f8f8f8;
43 | display: grid;
44 | place-items: center;
45 | `
46 | const Content = styled.div`
47 | padding: 100px;
48 | background-color: white;
49 | border-radius: 5px;
50 | box-shadow: 0 1px 3px gray;
51 | text-align: center;
52 | `
53 | const AmazonLogo = styled.img`
54 | height: 100px;
55 | margin-bottom: 40px;
56 | `
57 | const LoginButton = styled.button`
58 | margin-top: 50px;
59 | background-color: #f0c14b;
60 | height: 40px;
61 | border: 2px solid #a88734;
62 | border-radius: 4px;
63 | padding: 4px 8px;
64 | cursor: pointer;
65 | `
--------------------------------------------------------------------------------
/src/Product.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { db } from './firebase'
4 |
5 | function Product({ title, price, rating, image, id }) {
6 |
7 | const addToCart = () => {
8 | console.log(id);
9 | const cartItem = db.collection("cartItems").doc(id);
10 | cartItem.get()
11 | .then((doc)=>{
12 | console.log(doc);
13 | if(doc.exists){
14 | cartItem.update({
15 | quantity: doc.data().quantity + 1
16 | })
17 | } else {
18 | db.collection("cartItems").doc(id).set({
19 | name: title,
20 | image: image,
21 | price: price,
22 | quantity: 1
23 | })
24 | }
25 | })
26 | }
27 |
28 | return (
29 |
30 |
31 | {title}
32 |
33 |
34 | ${price}
35 |
36 |
37 | {
38 | Array(rating)
39 | .fill()
40 | .map(rating => ⭐
)
41 | }
42 |
43 |
44 |
45 |
48 | Add to Cart
49 |
50 |
51 |
52 | )
53 | }
54 |
55 | export default Product
56 |
57 | const Container = styled.div`
58 | background-color: white;
59 | z-index: 100;
60 | flex: 1;
61 | padding: 20px;
62 | margin: 10px;
63 | max-height: 400px;
64 | display: flex;
65 | flex-direction: column;
66 | `
67 | const Title = styled.span``
68 | const Price = styled.span`
69 | font-weight: 500;
70 | margin-top: 3px;
71 | `
72 | const Rating = styled.div`
73 | display: flex;
74 | `
75 | const Image = styled.img`
76 | max-height: 200px;
77 | object-fit: contain;
78 | `
79 |
80 | const ActionSection = styled.div`
81 | margin-top: 12px;
82 | display: grid;
83 | place-items: center;
84 | `
85 |
86 | const AddToCartButton = styled.button`
87 | width: 100px;
88 | height: 30px;
89 | background-color: #f0c14b;
90 | border: 2px solid #a88734;
91 | border-radius: 2px;
92 | cursor: pointer;
93 | `
94 |
--------------------------------------------------------------------------------
/src/firebase.js:
--------------------------------------------------------------------------------
1 | import firebase from 'firebase'
2 |
3 | const firebaseApp = firebase.initializeApp({
4 | apiKey: "AIzaSyBL6yj1-ZNcR6qvN22_CnNNmrD90ezz3vg",
5 | authDomain: "clone-mar21.firebaseapp.com",
6 | projectId: "clone-mar21",
7 | storageBucket: "clone-mar21.appspot.com",
8 | messagingSenderId: "781350103372",
9 | appId: "1:781350103372:web:a86eda03286270903707e9",
10 | measurementId: "G-4RQMTWZN67"
11 | });
12 |
13 | const db = firebase.firestore();
14 | const auth = firebase.auth();
15 | const provider = new firebase.auth.GoogleAuthProvider()
16 |
17 | export { db, auth, provider };
--------------------------------------------------------------------------------
/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 reportWebVitals from './reportWebVitals';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want to start measuring performance in your app, pass a function
15 | // to log results (for example: reportWebVitals(console.log))
16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17 | reportWebVitals();
18 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------