diff --git a/src/components/App.js b/src/components/App.js
index 6b15d49f8..0eccdd94f 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -1,18 +1,20 @@
-import React from "react";
+import React, { useState } from "react";
import ShoppingList from "./ShoppingList";
import itemData from "../data/items";
function App() {
+ const [isLightMode, setIsLightMode] = useState(false)
+ const appClass = isLightMode ? "App dark" : "App light"
- // 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 toggleLightMode = () => {
+ setIsLightMode(() => isLightMode ? false : true)
+ }
return (
Shopster
-
+
diff --git a/src/components/Item.js b/src/components/Item.js
index b833ecf8e..6f2d0f944 100644
--- a/src/components/Item.js
+++ b/src/components/Item.js
@@ -1,11 +1,17 @@
-import React from "react";
+import React, { useState } from "react";
function Item({ name, category }) {
+ const [isInCart, setIsInCart] = useState(false)
+ const cartStatusClass = isInCart ? 'in-cart' : ''
+ const addToCartText = isInCart ? "Remove from Cart" : 'Add to Cart'
+ const toggleInCartStatus = () => {
+ setIsInCart(() => isInCart ? false : true)
+ }
return (
-
+
{name}
{category}
-
+
);
}
diff --git a/src/components/ShoppingList.js b/src/components/ShoppingList.js
index a48d82615..971a9a154 100644
--- a/src/components/ShoppingList.js
+++ b/src/components/ShoppingList.js
@@ -1,11 +1,19 @@
-import React from "react";
+import React, { useState } from "react";
import Item from "./Item";
function ShoppingList({ items }) {
+ const [selectedCategory, setSelectedCategory] = useState('All')
+ const filteredItems = items.filter(item => {
+ return selectedCategory === "All" ? true : item.category === selectedCategory
+ })
+ const handleCategorySelection = (event) => {
+ const newCategory = event.target.querySelector('option:checked').value;
+ setSelectedCategory(newCategory)
+ }
return (
-
- {items.map((item) => (
+ {filteredItems.map((item) => (
))}