diff --git a/src/components/App.js b/src/components/App.js index 6b15d49f8..962531113 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,22 +1,26 @@ -import React from "react"; -import ShoppingList from "./ShoppingList"; -import itemData from "../data/items"; +import React, { useState } from "react" +import ShoppingList from "./ShoppingList" +import itemData from "../data/items" function App() { + const [isDark, setIsDark] = useState(false) - // replace 'false' with a state variable that can be toggled between true and false - // this will be used for the Dark Mode Toggle feature - const appClass = false ? "App dark" : "App light" + const handleClick = () => { + setIsDark(!isDark) + } + + const appClass = isDark ? "App dark" : "App light" + const buttonText = isDark ? "Light Mode" : "Dark Mode" return (

Shopster

- +
- ); + ) } -export default App; +export default App diff --git a/src/components/Item.js b/src/components/Item.js index b833ecf8e..fe03b0298 100644 --- a/src/components/Item.js +++ b/src/components/Item.js @@ -1,13 +1,24 @@ -import React from "react"; +import React, { useState } from "react" function Item({ name, category }) { + const [isInCart, setIsInCart] = useState(false) + + const handleClick = () => { + setIsInCart(!isInCart) + } + + const itemClass = isInCart ? "in-cart" : "" + const buttonText = isInCart ? "Remove from Cart" : "Add to Cart" + return ( -
  • +
  • {name} {category} - +
  • - ); + ) } -export default Item; +export default Item diff --git a/src/components/ShoppingList.js b/src/components/ShoppingList.js index a48d82615..aad22926c 100644 --- a/src/components/ShoppingList.js +++ b/src/components/ShoppingList.js @@ -1,11 +1,23 @@ -import React from "react"; -import Item from "./Item"; +import React, { useState } from "react" +import Item from "./Item" function ShoppingList({ items }) { + const [filteredItems, setFilterItems] = useState(items) + + const handleFilterChange = ({ target: { value } }) => { + const newFilteredItems = items.filter((item) => { + if (value === "All") return true + + return item.category === value + }) + + setFilterItems(newFilteredItems) + } + return (
    - @@ -13,12 +25,12 @@ function ShoppingList({ items }) {
    - ); + ) } -export default ShoppingList; +export default ShoppingList