From 067e18bde0ed879f69245e9fb6afe6bd4a77176f Mon Sep 17 00:00:00 2001 From: Gowtham Jangiti Date: Mon, 14 Oct 2024 18:09:57 +0530 Subject: [PATCH 1/2] Initial Setup --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e728852..9a86a8d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", + "antd": "^5.18.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", From f50480390cbd6ad4d09c5379c93045638e1072e1 Mon Sep 17 00:00:00 2001 From: Gowtham Jangiti Date: Mon, 14 Oct 2024 18:20:24 +0530 Subject: [PATCH 2/2] Completed --- src/App.js | 45 ++++++++++++++++++- src/Components/AddFoodForm.jsx | 80 ++++++++++++++++++++++++++++++++++ src/Components/FoodBox.jsx | 32 ++++++++++++++ src/Components/Search.jsx | 22 ++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/Components/AddFoodForm.jsx create mode 100644 src/Components/FoodBox.jsx create mode 100644 src/Components/Search.jsx diff --git a/src/App.js b/src/App.js index 3784575..885f191 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,28 @@ import logo from './logo.svg'; import './App.css'; +import jsonData from "./foods.json"; +import { useState } from "react"; +import "./App.css"; +import FoodBox from "./Components/FoodBox"; +import { Row, Divider } from "antd"; +import AddFoodForm from "./Components/AddFoodForm"; +import Search from "./Components/Search"; function App() { + const [foods, setFoods] = useState(jsonData); + + function handleSearch(searchQuery) { + const filterFoods = jsonData.filter((food) => + food.name.toLowerCase().includes(searchQuery.toLowerCase()) + ); + + setFoods(filterFoods); + } + + const deleteFood = (calories)=>{ + const updatedFoods = foods.filter((food) => food.calories!== calories); + setFoods(updatedFoods); + } return (
@@ -18,8 +39,30 @@ function App() { Learn React
+ + + + +

Food List

+
+ { + foods.length>0? + ( + + {foods.map((food, index) => ( + deleteFood(food.calories)} /> + ))} + + ): + ( +
+

Oop! There is no more content to show

+ +
+ ) + }
); } -export default App; +export default App; \ No newline at end of file diff --git a/src/Components/AddFoodForm.jsx b/src/Components/AddFoodForm.jsx new file mode 100644 index 0000000..1d0d810 --- /dev/null +++ b/src/Components/AddFoodForm.jsx @@ -0,0 +1,80 @@ +import React, { useState } from "react"; +import { Form, Input, Button } from "antd"; + +const AddFoodForm = ({ foods, addNewFood }) => { + const [showBtn, setShowBtn] = useState(false); + const [form] = Form.useForm(); + const onFinish = (newFood) => { + addNewFood([newFood, ...foods]); + form.resetFields(); + }; + + return ( +
+ {showBtn ? ( + <> +
+ + + + + + + + + + + + + + + + + + + +
+ + + ) : ( + + )} +
+ ); +}; + +export default AddFoodForm; \ No newline at end of file diff --git a/src/Components/FoodBox.jsx b/src/Components/FoodBox.jsx new file mode 100644 index 0000000..8666a58 --- /dev/null +++ b/src/Components/FoodBox.jsx @@ -0,0 +1,32 @@ +import { Card, Button, Col } from "antd"; +const FoodBox = ({ food , deleteFood }) => { + return ( + + + } + > +

Servings: {food.servings}

+

+ Total Calories: {food.calories} Kcal +

+ +
+ + ); +}; + +export default FoodBox; \ No newline at end of file diff --git a/src/Components/Search.jsx b/src/Components/Search.jsx new file mode 100644 index 0000000..46b4745 --- /dev/null +++ b/src/Components/Search.jsx @@ -0,0 +1,22 @@ +import React from 'react' +import {Divider,Input} from "antd" +const Search = ({handleSearch}) => { + function handleChange(e){ + const searchQuery= e.target.value ; + handleSearch(searchQuery) + } + return ( + <> + Search + + + + + ) +} + +export default Search \ No newline at end of file