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", 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 (
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 ( + <> +