Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,284 changes: 2,850 additions & 434 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.22.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down Expand Up @@ -34,5 +35,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"tailwindcss": "^3.4.15"
}
}
38 changes: 0 additions & 38 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +0,0 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
64 changes: 46 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
import logo from './logo.svg';
import './App.css';
import React, { useState } from 'react';
import foods from './foods.json';
import FoodBox from './components/FoodBox';
import AddFoodForm from './components/AddFoodFrom'
import Search from './components/Search';

function App() {
const [foodList, setFoodList] = useState(foods);
const [searchTerm, setSearchTerm] = useState('');
const [isFormVisible, setIsFormVisible] = useState(true); // State for form visibility

const addFood = (newFood) => {
setFoodList([...foodList, newFood]);
};

const deleteFood = (foodName) => {
setFoodList(foodList.filter(food => food.name !== foodName));
};

const filteredFoods = foodList.filter(food =>
food.name.toLowerCase().includes(searchTerm.toLowerCase())
);

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div className="container mx-auto p-4">
<h1 className='text-black text-center text-2xl'>Search</h1>
<Search searchTerm={searchTerm} setSearchTerm={setSearchTerm} />

<h1 className='text-black text-center text-2xl'>Add Food Entry</h1>
<button
onClick={() => setIsFormVisible(!isFormVisible)}
className="mb-4 px-4 py-2 bg-blue-500 text-white rounded justify-center"
>
{isFormVisible ? 'Hide Form' : 'Add New Food'}
</button>

{isFormVisible && <AddFoodForm addFood={addFood} />}

<h1 className='text-black text-center text-2xl'>Food List</h1>
{filteredFoods.length === 0 ? (
<p>No foods available. Please add some!</p>
) : (
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-4">
{filteredFoods.map(food => (
<FoodBox key={food.name} food={food} deleteFood={deleteFood} />
))}
</div>
)}
</div>
);
}

export default App;
export default App;
32 changes: 32 additions & 0 deletions src/components/AddFoodFrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useState } from 'react';
import { Input, Button } from 'antd';

function AddFoodForm({ addFood }) {
const [name, setName] = useState('');
const [image, setImage] = useState('');
const [calories, setCalories] = useState('');
const [servings, setServings] = useState('');

const handleSubmit = (e) => {
e.preventDefault();
addFood({ name, image, calories: Number(calories), servings: Number(servings) });
setName('');
setImage('');
setCalories('');
setServings('');
};

return (
<div className="flex justify-center mb-4">
<form onSubmit={handleSubmit} className="w-full max-w-md">
<Input value={name} onChange={(e) => setName(e.target.value)} placeholder="Name" className="mb-2" />
<Input value={image} onChange={(e) => setImage(e.target.value)} placeholder="Image URL" className="mb-2" />
<Input value={calories} onChange={(e) => setCalories(e.target.value)} placeholder="Calories" className="mb-2" />
<Input value={servings} onChange={(e) => setServings(e.target.value)} placeholder="Servings" className="mb-2" />
<Button type="submit" className='bg-blue-400 text-white border border-black'>Add Food</Button>
</form>
</div>
);
}

export default AddFoodForm;
15 changes: 15 additions & 0 deletions src/components/FoodBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Card, Button } from 'antd';

function FoodBox({ food, deleteFood }) {
return (
<Card title={food.name} className="flex flex-col items-center p-4 border border-black">
<img src={food.image} alt={food.name} className="w-auto h-auto mb-2" />
<p>Calories: {food.calories}</p>
<p>Servings: {food.servings}</p>
<Button onClick={() => deleteFood(food.name)} type="danger" className='text-white bg-red-500 border border-black'>Delete</Button>
</Card>
);
}

export default FoodBox;
17 changes: 17 additions & 0 deletions src/components/Search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Input } from 'antd';

function Search({ searchTerm, setSearchTerm }) {
return (
<div className="flex justify-center mb-4">
<Input
placeholder="Search food..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="w-auto"
/>
</div>
);
}

export default Search;
16 changes: 3 additions & 13 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
@tailwind base;
@tailwind components;
@tailwind utilities;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'antd/dist/reset.css';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand Down
8 changes: 8 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
}