diff --git a/src/AddFoodForm.js b/src/AddFoodForm.js new file mode 100644 index 0000000..0f5f7be --- /dev/null +++ b/src/AddFoodForm.js @@ -0,0 +1,78 @@ +import { useState } from 'react'; +import { Divider, Input, Button } from 'antd'; + +function AddFoodForm(props) { + const [newFood, setNewFood] = useState({ + name: '', + image: '', + calories: '', + servings: '', + }); + + const handleInputChange = (e) => { + const { name, value } = e.target; + setNewFood({ ...newFood, [name]: value }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + + // Check if all fields are filled before adding the new food + if (newFood.name && newFood.image && newFood.calories && newFood.servings) { + // Call the onAddFood function passed from the parent component + props.onAddFood(newFood); + + // Reset the form after submitting + setNewFood({ + name: '', + image: '', + calories: '', + servings: '', + }); + } + }; + + return ( +
+ Add Food Entry + + + + + + + + + + + + + + +
+ ); +} + +export default AddFoodForm; diff --git a/src/App.css b/src/App.css index 74b5e05..6bc0a61 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,19 @@ .App { - text-align: center; + margin: 10px; } -.App-logo { - height: 40vmin; - pointer-events: none; +Button { + margin: 10px 0; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; +.feedback { display: flex; flex-direction: column; - align-items: center; justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; + align-items: center; + padding: 50px; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.feedback span { + font-size: 200px; } diff --git a/src/App.js b/src/App.js index 3784575..4c09d09 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,76 @@ -import logo from './logo.svg'; +// import logo from './logo.svg'; +import { useState } from 'react'; import './App.css'; +import { Row, Divider, Button} from 'antd'; +import FoodBox from './FoodBox'; +import AddFoodForm from './AddFoodForm'; +import Search from './Search'; +import foods from './foods.json'; function App() { + const [foodData, setFoodData] = useState(foods.map((food) => ({ ...food, id: food.name }))); + const [filteredFoodData, setFilteredFoodData] = useState(foodData); + const [showAddForm, setShowAddForm] = useState(false); + + const handleAddFood = (newFood) => { + // Use food name as id + const foodWithId = { ...newFood, id: newFood.name }; + + setFoodData([foodWithId, ...foodData]); + setFilteredFoodData([foodWithId, ...filteredFoodData]); + }; + + const handleDeleteFood = (id) => { + const updatedFoodData = foodData.filter((food) => food.id !== id); + setFoodData(updatedFoodData); + setFilteredFoodData(updatedFoodData); + }; + + const handleSearch = (query) => { + const filteredData = foodData.filter((food) => + food.name.toLowerCase().includes(query.toLowerCase()) + ); + setFilteredFoodData(filteredData); + }; + + const toggleAddForm = () => { + setShowAddForm(!showAddForm); + }; + return (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+ + +

Food List

+
+ + {/* Display AddFoodForm if showAddForm is true */} + {showAddForm && } + + {/* Toggle display of AddFoodForm */} + + + {/* Display Search component */} + + + Food List + + + {/* Render the list of Food Box components */} + {foodData.length === 0 ? ( +
+

Oops! There is no more content to show.

+ Ø +
+ ) : ( + foodData.map((food) => ( + + )) + )} +
); } - export default App; diff --git a/src/FoodBox.js b/src/FoodBox.js new file mode 100644 index 0000000..52060a5 --- /dev/null +++ b/src/FoodBox.js @@ -0,0 +1,29 @@ +import { Card, Col, Button } from 'antd'; + +function FoodBox({ food, onDelete }) { + const handleDelete = () => { + // Call the onDelete function with the food name when the delete button is clicked + onDelete(food.name); + }; + + return ( + + + food +

Calories: {food.calories}

+

Servings: {food.servings}

+

+ Total Calories: {food.calories * food.servings} kcal +

+ +
+ + ); +} + +export default FoodBox; diff --git a/src/Search.js b/src/Search.js new file mode 100644 index 0000000..f8dae81 --- /dev/null +++ b/src/Search.js @@ -0,0 +1,18 @@ +import { Divider, Input } from 'antd'; + +function Search({ onSearch }) { + const handleSearch = (e) => { + onSearch(e.target.value); + }; + + return ( + <> + Search + + + + + ); +} + +export default Search;