//===================================================================
Added localStorage for Favorites and Cart Items.
//===================================================================
-
Only render the "Place Order" button if there are items in the cart
-
Change the trash icon to a filled-in trash icon when hovering over it
Filled trash icon to use when hovering:
Empty trash icon to use when NOT hovering:
//===================================================================
Let our user place their order!
Clicking the "Place Order" button should:
- Change the text to "Ordering..."
- Timeout for 3 seconds (to simulate an order being placed)
- Log "Order placed!" to the console
- Empty out the cart
//===================================================================
Calculate the total cost of the items in the cart and display it on the Cart page
- Usually the item in the database will have it's own cost saved, but we're assuming every item we sell costs $5.99, so you can just hard code that cost in
- To very easily display the total cost in US dollars (or whatever currency you want), use the following:
<number>.toLocaleString("en-US", {style: "currency", currency: "USD"})
//===================================================================
Change the cart icon in the header to display the full cart icon if there are any items in the cart
Full class name to use WHEN ITEMS IN CART: "ri-shopping-cart-fill ri-fw ri-2x"
Full class name to use WHEN CART IS EMPTY: "ri-shopping-cart-line ri-fw ri-2x"
//===================================================================
Change the plus icon to a full shopping cart icon when an image is already in the cart. This should display whether the image is being hovered or not (like the favorite icon).
Icon to use when item already in cart:
Hints: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some https://stackoverflow.com/a/8217584
//===================================================================
Setup context to manage items in an array called cartItems
. This will be an array of image objects.
- Add the
cartItems
state to context. (Array) - Add function to add an image to the cart. (Takes the full image object as parameter)
- Make it so clicking the plus icon on the image adds the item to the cart. (Console.log the cart items array to see that it's working)
//===================================================================
Add propTypes to the Image component
- className should be a string
- img should be an object, specifically an object with
id
,url
, andisFavorite
properties a. Hint: Specifying the properties of an object is called and object's "shape"
https://reactjs.org/docs/typechecking-with-proptypes.html#proptypes
//===================================================================
Make the image display the filled heart icon when it's already favorited
Logic to follow:
- If the image is favorited, display the filled heart icon always
- Otherwise, if the image being hovered on, display the heart outline instead
- If it isn't favorited OR hovered on, don't display anything
Remember to make it so clicking the filled heart icon ALSO runs the toggleFavorite function!
Filled heart icon:
//===================================================================
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
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.
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.
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.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify