diff --git a/.firebase/hosting.YnVpbGQ.cache b/.firebase/hosting.YnVpbGQ.cache index 0e84025..071724d 100644 --- a/.firebase/hosting.YnVpbGQ.cache +++ b/.firebase/hosting.YnVpbGQ.cache @@ -3,25 +3,25 @@ logo192.png,499162500000,3ee59515172ee198f3be375979df15ac5345183e656720a381b8872 logo512.png,499162500000,ee7e2f3fdb8209c4b6fd7bef6ba50d1b9dba30a25bb5c3126df057e1cb6f5331 manifest.json,499162500000,aff3449bdc238776f5d6d967f19ec491b36aed5fb7f23ccff6500736fd58494a robots.txt,499162500000,bfe106a3fb878dc83461c86818bf74fc1bdc7f28538ba613cd3e775516ce8b49 -asset-manifest.json,1586097073676,a76761b81944b6fcac87ed8aec6d728697cbf65cec8a73271f52a65cfdeb2709 -index.html,1586097073676,a43ae15c3a95f4b1c5a2f1fef5824807e161f5024f799f24af67a462e7ef12ff -precache-manifest.345c3d7702ca008c4df7e0a6ad37d438.js,1586097073676,57a3b1ff417c80ea7aeab8ac01ae81d88da30b4e2981a6ce342c28a2766ec663 -service-worker.js,1586097073676,748738413e32b85ac16f4ff5684e2d547b08adbf745b1c6cc13c7815c46b445e -static/css/main.f04d35b9.chunk.css,1586097073669,e0eb093d35d2a66c76ef95d1e0df226f18b6fba36a9de8f30760b692fc3ff8f2 -static/css/main.f04d35b9.chunk.css.map,1586097073675,1c000a1738e717ea4e2498b3f966a22626e2b3a8aaf061437f8323728368a602 -static/js/2.c518f810.chunk.js.LICENSE.txt,1586097073673,6ff0efb0ab65b72f2b7f182b35c121880d1bd47a1dd25559ca128f416af5b426 -static/js/main.3c0cb98a.chunk.js,1586097073669,d585c3fbb89a7f5dfcbb2f9f099ba00ad871ad1e1e325b26fc8f61af8c16eeea -static/js/runtime-main.3163e38f.js,1586097073672,8d77f0e8b689aa0ca4c94ec20c0baed82fb38953f5e9d57cb405cebde0941a1a -static/js/runtime-main.3163e38f.js.map,1586097073685,50cdf64ac014eff3eeb3b70c1c3714da394f6c1e2c07ee658d35e8c09497b78f -static/media/helmet.223db1ca.png,1586097073672,77eb8f7e941044622b89e2130843e0217f3ae21defc2c82db9f154c4a6ca9f7e -static/media/logo.888f17aa.png,1586097073672,d86dcdc0edb6148560ce8f67a02d758b41f9e2e71096fdfbf774fb890e4cedcc -static/media/logo2.2ce2face.png,1586097073667,12d0be855bb04106bac3f0a351fe80abe844f4869301b09dfe6dc80ff44f4465 -static/media/rider.6ec113cc.png,1586097073672,e9e79bcceb08eddb87b7b664d34abc3077b0c26f9b2259da8b355c90f2e9238e -static/css/2.de424728.chunk.css,1586097073672,5e77f5d7ebf898c5c1b9cb53676d9fcd3e499abfd52174bebf6fc9ff1a449f74 -static/js/main.3c0cb98a.chunk.js.map,1586097073676,a9ddfc662f8e550c32447a2d9441a5c839fcbf47f10c658cdab98c3fb3a70495 -static/media/signup-bg.a5fdc065.png,1586097073672,ef5beeafb60fbceb04c91f1daf58ee46c60d1d52a5c4ce650f998ed28635f145 -static/media/bannerbackground.74e060db.png,1586097073672,4cc25ed8b1c84ac6c143e476ebfa2dac2c865ea5dd755d4a49e766e703ff6e21 -static/js/2.c518f810.chunk.js,1586097073673,a0b2c2adeee1334df343a57397fb06ec531885ac8ca3a5625520af218c1f0355 -static/media/ordercomplete.e34eab0b.png,1586097073672,feffb95331e23a1d8f5a026d2440b11b81238f2302a650377de3f135a037b7ba -static/css/2.de424728.chunk.css.map,1586097073676,d799f449acdbef9a84807b7ef0891040908f1175f7950f7af3c8250426a92cf1 -static/js/2.c518f810.chunk.js.map,1586097073686,077aedc836e5c6a3616fd6685ec0ae8963e5e3d0bd5a7c83f63d79ead10d5e88 +asset-manifest.json,1586887277172,afe1c09fec06eb8be20a88335e8ede428773c9fd99f892363224f756fe9850af +index.html,1586887277172,39db4283bd9ade0cc3fda34c7bfc6bc705e5fe55ce44c5629cf871a030d31bb7 +precache-manifest.a63de4996e9538f998bfae5d9b5a0d11.js,1586887277172,acfac92e1a847955c7473e3001c4656b82b3a2b92d42749fe31b2b59fb21d97d +service-worker.js,1586887277172,8e826118ddb2f4a9b99e52f515308b4e88cfe4ad39af358f64a5fd26f22114cc +static/css/main.07d24919.chunk.css,1586887277158,dcb45f87731e55aae9e34498851cfb08ef5ee5a74331aedb55b167ef98943987 +static/css/main.07d24919.chunk.css.map,1586887277164,da1c66ad3e886ce91163bb1a537ce80031a72f8115f24334e28868c5e8a5fd7f +static/js/2.83b8c8fe.chunk.js.LICENSE.txt,1586887277164,6ff0efb0ab65b72f2b7f182b35c121880d1bd47a1dd25559ca128f416af5b426 +static/js/runtime-main.3163e38f.js,1586887277163,8d77f0e8b689aa0ca4c94ec20c0baed82fb38953f5e9d57cb405cebde0941a1a +static/js/runtime-main.3163e38f.js.map,1586887277190,50cdf64ac014eff3eeb3b70c1c3714da394f6c1e2c07ee658d35e8c09497b78f +static/media/helmet.223db1ca.png,1586887277163,77eb8f7e941044622b89e2130843e0217f3ae21defc2c82db9f154c4a6ca9f7e +static/js/main.ae04c080.chunk.js,1586887277158,ba343e83f9c5ca1d5f9db7ba2f109d77a7dca6b38af408957320398ec084226a +static/media/logo.888f17aa.png,1586887277161,d86dcdc0edb6148560ce8f67a02d758b41f9e2e71096fdfbf774fb890e4cedcc +static/media/logo2.2ce2face.png,1586887277150,12d0be855bb04106bac3f0a351fe80abe844f4869301b09dfe6dc80ff44f4465 +static/media/rider.6ec113cc.png,1586887277163,e9e79bcceb08eddb87b7b664d34abc3077b0c26f9b2259da8b355c90f2e9238e +static/css/2.de424728.chunk.css,1586887277164,5e77f5d7ebf898c5c1b9cb53676d9fcd3e499abfd52174bebf6fc9ff1a449f74 +static/js/main.ae04c080.chunk.js.map,1586887277172,53cf4b34d7d2947fb6b9125fd63911a81251fbea952594f091c5b82934ab95a3 +static/media/signup-bg.a5fdc065.png,1586887277163,ef5beeafb60fbceb04c91f1daf58ee46c60d1d52a5c4ce650f998ed28635f145 +static/media/bannerbackground.74e060db.png,1586887277163,4cc25ed8b1c84ac6c143e476ebfa2dac2c865ea5dd755d4a49e766e703ff6e21 +static/media/ordercomplete.e34eab0b.png,1586887277162,feffb95331e23a1d8f5a026d2440b11b81238f2302a650377de3f135a037b7ba +static/css/2.de424728.chunk.css.map,1586887277165,d799f449acdbef9a84807b7ef0891040908f1175f7950f7af3c8250426a92cf1 +static/js/2.83b8c8fe.chunk.js,1586887277164,795f2aa25a20723048b351c19db86e62391560b9bf5b8914a598f454789f46cc +static/js/2.83b8c8fe.chunk.js.map,1586887277191,d197ea060c748f81f6e67bc6cd78dfaa4ebd5ea0983f42b8b86beb37afbabc7f diff --git a/src/App.js b/src/App.js index aba11f8..bf3543f 100644 --- a/src/App.js +++ b/src/App.js @@ -18,33 +18,32 @@ import { useEffect } from 'react'; function App() { const [cart , setCart] = useState([]); - console.log(cart.length) + // console.log(cart.length) - const [products, setProducts] = useState([]) + // const [products, setProducts] = useState([]) - useEffect(() => { - fetch('https://backend-ema-john.herokuapp.com/products') - .then(res => res.json()) - .then(data => { - // console.log("data from mongodb", data); - setProducts(data) - }) - }, []) + // useEffect(() => { + // fetch('red-onion-restaurant.herokuapp.com/products') + // .then(res => res.json()) + // .then(data => { + // setProducts(data) + // }) + // }, []) - useEffect(() => { - const savedCart = getDatabaseCart() - const productKeys = Object.keys(savedCart) - // console.log(productKeys); - if(cart.length){ - const previousCart = productKeys.map(existingId => { - const product = products.find(pd => pd.key === existingId) - product.quantity = savedCart[existingId] - return product - }) - setCart(previousCart) - } - }, [cart]) + // useEffect(() => { + // const savedCart = getDatabaseCart() + // const productKeys = Object.keys(savedCart) + // // console.log(productKeys); + // if(cart.length){ + // const previousCart = productKeys.map(existingId => { + // const product = products.find(pd => pd.key === existingId) + // product.quantity = savedCart[existingId] + // return product + // }) + // setCart(previousCart) + // } + // }, [cart]) const cartHandler = (data) => { const alreadyAdded = cart.find(crt => crt.id === data.id ); @@ -97,7 +96,7 @@ function App() {
- +
diff --git a/src/Components/FoodDetails/FoodDetails.js b/src/Components/FoodDetails/FoodDetails.js index 2ca96cf..e3e5f22 100644 --- a/src/Components/FoodDetails/FoodDetails.js +++ b/src/Components/FoodDetails/FoodDetails.js @@ -24,7 +24,7 @@ const FoodDetails = (props) => { console.log("data from mongodb", data); setCurrentFood(data) }) - }, []) + }, [id]) @@ -32,17 +32,23 @@ const FoodDetails = (props) => { // console.log( allFoods[0]); // console.log( foods[0]); - // const currentFood = allFoods.find(food=> food.id == id); + // const currentFood1 = allFoods.find(food=> food.id == id); console.log(currentFood); useState(() => { - if (currentFood.quantity){ + if (currentFood.quantity) { setQuantity(currentFood.quantity) } }, [currentFood.quantity]) + // useState(() => { + // if (currentFood1.quantity) { + // setQuantity(currentFood1.quantity) + // } + // }, [currentFood.quantity]) + const finalCartHandler = (currentFood) => { @@ -70,7 +76,7 @@ const FoodDetails = (props) => {

{currentFood.name}

{currentFood.description}

-

${(currentFood.price).toFixed(2)}

+

${currentFood.price}

@@ -106,11 +112,13 @@ const FoodDetails = (props) => {
- {currentFood.img.map(img=> )} + {/* {currentFood !== null && currentFood.img.map(img => Food pic)} */} + Food pic + Food pic
- + Food pic
diff --git a/src/Components/Foods/Foods.js b/src/Components/Foods/Foods.js index f9343ff..3e233e4 100644 --- a/src/Components/Foods/Foods.js +++ b/src/Components/Foods/Foods.js @@ -22,9 +22,14 @@ const Foods = (props) => { // console.log("data from mongodb", data); setFoods(data) }) - }, []) + }, [foods]) + console.log(foods); - const selectedFoods = foods.filter(food => food.category === selectedFoodType) + + const selectedFoods = foods!==null && foods.filter(food => food.category === selectedFoodType) + + + // console.log(selectedFoodType); return ( diff --git a/src/Components/Login/Login.js b/src/Components/Login/Login.js index 0209662..2206960 100644 --- a/src/Components/Login/Login.js +++ b/src/Components/Login/Login.js @@ -4,6 +4,8 @@ import { useForm } from 'react-hook-form'; import Logo from '../../Images/logo2.png'; import {Link} from 'react-router-dom'; import { useAuth } from './useAuth'; +import signInBtn from '../../Images/login-with-google-button.png' +import signOutBtn from '../../Images/logout.jpg' const Login = () => { @@ -25,6 +27,37 @@ const Login = () => { } // console.log(auth); + + const is_valid_email = email => /(.+)@(.+){2,}\.(.+){2,}/.test(email) + const hasNumber = input => /\d/.test(input) + + const handleChange = event => { + //perform validation + let isValid = true + if (event.target.name === "email") { + isValid = is_valid_email(event.target.value); + } + else if (event.target.name === "password") { + isValid = event.target.value.length > 8 && hasNumber(event.target.value); + } + } + + + //google + const handleSignIn = () => { + auth.signInWithGoogle() + .then(res => { + // console.log('redirect now'); + window.location.pathname = '/checkout' + }) + } + + const handleSignOut = () => { + auth.signOut() + .then(res => { + window.location.pathname = '/' + }) + } return ( @@ -34,14 +67,14 @@ const Login = () => { -
\ + { returningUser ?
- + {errors.email && Email is required}
@@ -63,7 +96,7 @@ const Login = () => { {errors.name && Name is required}
- + {errors.email && Email is required}
@@ -83,15 +116,37 @@ const Login = () => {
- + } +
+
Or
+ { + auth.user ? + // + + : + // + + } +
+ + + { errors.error &&

{errors.error}

} + + + + ); }; diff --git a/src/Components/Login/useAuth.js b/src/Components/Login/useAuth.js index b8f03cd..fca3406 100644 --- a/src/Components/Login/useAuth.js +++ b/src/Components/Login/useAuth.js @@ -34,6 +34,10 @@ export const PrivateRoute = ({ children, ...rest }) => { ); } +const getUser = user => { + const { displayName, email, photoURL } = user + return { name: displayName, email, photo: photoURL } +} const Auth = () => { const [user, setUser] = useState(null); useEffect(() => { @@ -68,11 +72,24 @@ const Auth = () => { }); - - - } + const signInWithGoogle = () => { + const provider = new firebase.auth.GoogleAuthProvider() + return firebase.auth().signInWithPopup(provider) + .then(res => { + // console.log(res); + const signedInUser = getUser(res.user) + setUser(signedInUser) + return res.user + }) + .catch(err => { + // console.log(err) + setUser(null) + return err.message + }); + } + const signOut = () => { return firebase.auth().signOut() .then(res => setUser(null)) @@ -81,6 +98,7 @@ const Auth = () => { user, signIn, signUp, + signInWithGoogle, signOut } } diff --git a/src/Images/login-with-google-button.png b/src/Images/login-with-google-button.png new file mode 100644 index 0000000..716e0b7 Binary files /dev/null and b/src/Images/login-with-google-button.png differ diff --git a/src/Images/logout.jpg b/src/Images/logout.jpg new file mode 100644 index 0000000..6a73c85 Binary files /dev/null and b/src/Images/logout.jpg differ