This is a cooking recipe website built using React for the front-end and Firebase for the back-end. It allows users to create, read, update, and delete recipes easily. The application features a user-friendly interface, search functionality, and the ability to manage ingredients. With Firebase handling data storage and real-time updates, users can seamlessly manage their favorite recipes. Major frameworks and libraries:
-
Install dependencies:
npm install
-
Start the front-end development server:
npm start
-
Install Firebase:
npm install firebase
Here's an interface summary for your cooking application, based on the provided screenshots:
-
Theme Customization:
-
View Recipe:
-
Initial Recipe Search:
-
Create a New Recipe:
-
Edit Recipe:
-
Delete Recipe:
This summary provides an overview of the core functionalities, focusing on recipe management and interface customization.
Old Version (useHistory):
import { useHistory } from 'react-router-dom';
const history = useHistory();
history.push(`/search?q=${term}`);
New Version (useNavigate):
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate(`/search?q=${search}`);
- Use
useNavigate
: Simplifies navigation in React Router v6, making code more concise and modern.
Old Version:
const fetchData = async () => {
const res = await fetch(url);
};
New Version:
const controller = new AbortController();
const signal = controller.signal;
const res = await fetch(url, { signal });
- Use
AbortController
: Manages async operations effectively, preventing memory leaks and unhandled errors.
Old Version:
<Switch>
<Route exact path="/">
<Home />
</Route>
</Switch>
New Version:
<Routes>
<Route path="/" element={<Home />} />
</Routes>
- Use
Routes
: Enhances code readability and performance in React Router v6.
Old Version:
useEffect(() => {
fetchData();
}, []);
New Version:
useEffect(() => {
const unsubscribe = projectFirestore.collection('recipes').onSnapshot((snapshot) => {
// Update state with new data
});
return () => unsubscribe();
}, []);
- Use
onSnapshot
: Fetches initial data and listens for changes, streamlining the data handling process.
Here’s the updated README format with code improvements:
Old Version:
const handleEdit = (recipe) => {
// Update recipe logic without modal
};
New Version (with Modal):
const handleEdit = (recipe) => {
setEditing(recipe.id);
setUpdatedRecipe({
title: recipe.title,
cookingTime: recipe.cookingTime.replace(' minutes', ''),
method: recipe.method,
ingredients: recipe.ingredients
});
};
{editing && (
<div className={`modal ${mode}`}>
<div className="modal-content">
<label>
<span>Recipe Title:</span>
<input
type="text"
value={updatedRecipe.title}
onChange={(e) => setUpdatedRecipe({ ...updatedRecipe, title: e.target.value })}
/>
</label>
{/* Additional form fields for ingredients, method, cooking time */}
<button onClick={() => handleUpdate(editing)} className="btn">Save</button>
<button onClick={() => setEditing(null)} className="btn">Cancel</button>
</div>
</div>
)}
- Modal Addition: Added a modal that allows users to edit recipes in an overlay form.
- Dynamic Modal Styling: The modal styling adapts based on the
mode
, supporting both light and dark themes. - Form Content: The form content is similar to the creation form, allowing users to modify all fields.