Skip to content

Commit

Permalink
done add
Browse files Browse the repository at this point in the history
  • Loading branch information
arifpro committed Apr 17, 2020
1 parent 74b31df commit 18fc90f
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 61 deletions.
44 changes: 22 additions & 22 deletions .firebase/hosting.YnVpbGQ.cache
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 23 additions & 24 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -97,7 +96,7 @@ function App() {
</Route>
<Route path="/food/:id">
<Header cart={cart}></Header>
<FoodDetails cart={cart} cartHandler={cartHandler}></FoodDetails>
<FoodDetails cart={cart} cartHandler={cartHandler}></FoodDetails>
<Footer></Footer>
</Route>
<PrivateRoute path="/checkout">
Expand Down
20 changes: 14 additions & 6 deletions src/Components/FoodDetails/FoodDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,31 @@ const FoodDetails = (props) => {
console.log("data from mongodb", data);
setCurrentFood(data)
})
}, [])
}, [id])



// setCurrentFood(allFoods.find(food => food.id == id))
// 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) => {
Expand Down Expand Up @@ -70,7 +76,7 @@ const FoodDetails = (props) => {
<h1><strong>{currentFood.name}</strong></h1>
<p className="my-5 desc">{currentFood.description}</p>
<div className="d-flex my-4">
<h2 className="price"><strong>${(currentFood.price).toFixed(2)}</strong></h2>
<h2 className="price"><strong>${currentFood.price}</strong></h2>

<div className="d-flex align-items-center">
<div className="cart-controller ml-3 btn">
Expand Down Expand Up @@ -106,11 +112,13 @@ const FoodDetails = (props) => {
</Link>

<div className="more-images mt-5 ">
{currentFood.img.map(img=> <img className="mr-4" height="150px" src={img} alt=""/>)}
{/* {currentFood !== null && currentFood.img.map(img => <img className="mr-4" height="150px" src={img} alt="Food pic" />)} */}
<img className="mr-4" height="150px" src={currentFood.img} alt="Food pic" />
<img className="mr-4" height="150px" src={currentFood.img} alt="Food pic" />
</div>
</div>
<div className="col-md-6">
<img className="img-fluid" src={currentFood.img[0]} alt=""/>
<img className="img-fluid" src={currentFood.img} alt="Food pic"/>
</div>

</div>
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Foods/Foods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
63 changes: 59 additions & 4 deletions src/Components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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 (
Expand All @@ -34,14 +67,14 @@ const Login = () => {
<Link to="/">
<img src={Logo} alt=""/>
</Link>
</div>\
</div>
{
returningUser ?
<form onSubmit={handleSubmit(onSubmit)} className="py-5">


<div className="form-group">
<input name="email" className="form-control" ref={register({ required: true })} placeholder="Email"/>
<input type="email" onBlur={handleChange} name="email" className="form-control" ref={register({ required: true })} placeholder="Email"/>
{errors.email && <span className="error">Email is required</span>}
</div>
<div className="form-group">
Expand All @@ -63,7 +96,7 @@ const Login = () => {
{errors.name && <span className="error">Name is required</span>}
</div>
<div className="form-group">
<input name="email" className="form-control" ref={register({ required: true })} placeholder="Email"/>
<input type="email" onBlur={handleChange} name="email" className="form-control" ref={register({ required: true })} placeholder="Email"/>
{errors.email && <span className="error">Email is required</span>}
</div>
<div className="form-group">
Expand All @@ -83,15 +116,37 @@ const Login = () => {
<label onClick={() => setReturningUser(true)}>Already Have an Account?</label>
</div>
</form>

}

<div className="logo text-center py-4">
<br /><h5>Or</h5>
{
auth.user ?
// <button onClick={auth.signOut}>Sign out</button>
<button onClick={handleSignOut}>
<img src={signOutBtn} alt="" />
</button>
:
// <button onClick={auth.signInWithGoogle}>Sign in with Google</button>
<button onClick={handleSignIn}>w
<img src={signInBtn} alt="" />
</button>
}
</div>




</div>
{
errors.error && <p style={{ color: 'red' }}>{errors.error}</p>
}





</div>
);
};
Expand Down
24 changes: 21 additions & 3 deletions src/Components/Login/useAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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))
Expand All @@ -81,6 +98,7 @@ const Auth = () => {
user,
signIn,
signUp,
signInWithGoogle,
signOut
}
}
Expand Down
Binary file added src/Images/login-with-google-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Images/logout.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 18fc90f

Please sign in to comment.