+
Skip to content

vickyzhang7/React-Firebase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React-Firebase Project

Project Overview

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:

  • JavaScript
  • React
  • HTML
  • CSS
  • Firebase

(back to top)

Installation and Running

Front-End (React Application)

  1. Install dependencies:

    npm install
  2. Start the front-end development server:

    npm start

Back-End

  1. Install Firebase:

    npm install firebase

Here's an interface summary for your cooking application, based on the provided screenshots:

Interface Screenshots

  1. Theme Customization:

    • Users can customize the theme color of the application, choosing between options like red or dark mode for a personalized interface experience.

      Screenshot 2024-06-29 at 10 45 37 PM Screenshot 2024-06-29 at 10 45 42 PM
  2. View Recipe:

    • Clicking "Cook This" expands the recipe details, displaying the full list of ingredients and step-by-step cooking instructions.

      Screenshot 2024-06-29 at 10 45 21 PM
  3. Initial Recipe Search:

    • When users first access the application, they can search for recipes. The search results display the recipe name, cooking time, and a brief description. Users can click "Cook This" to view details or "Edit" to modify the recipe.

      Screenshot 2024-06-29 at 11 19 23 PM
  4. Create a New Recipe:

    • Users can create a new recipe by clicking the "Create Recipe" button. They input the recipe title, ingredients, method, and cooking time. Once filled out, clicking "Submit" adds the recipe to the list.

      Screenshot 2024-06-29 at 10 47 03 PM
  5. Edit Recipe:

    • To edit an existing recipe, users click the "Edit" button. This opens a form with the current recipe details, allowing users to update ingredients, methods, or cooking time.

      Screenshot 2024-06-29 at 11 14 01 PM
  6. Delete Recipe:

    • Users can delete a recipe by clicking the trash icon. A confirmation dialog appears to ensure the user wants to delete the recipe.

      Screenshot 2024-06-29 at 10 47 48 PM

This summary provides an overview of the core functionalities, focusing on recipe management and interface customization.

Code Improvements

1. React Router Update

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.

2. useFetch Hook Optimization

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.

3. Switching from Switch to Routes

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.

4. Fetching Data on Component Mount

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:

5. Update Function with Modal

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载