This web application allows users to search for product details using the OpenFoodFacts API and provides a paginated view of product lists. It displays detailed information about each product, such as ingredients, nutrition facts, and labels. The app allows users to search, sort, and filter products by category.
- Product Search: Search for products using keywords.
- Product Sort: Sort products by name, category, or other criteria.
- Category Filter: Filter products based on selected categories.
- Pagination: Navigate through the list of products.
- Product Details: View detailed information about each product, including ingredients, nutrition facts, and labels.
- Frontend: React, Tailwind CSS
- API: OpenFoodFacts
- Clone the repository:
git clone https://github.com/faizanr27/food-facts.git
- Navigate into the project directory:
cd food-facts
- Install dependencies:
npm install
- Run the development server:
npm run dev
.
├── src
│ ├── components
| | ├── Navbar.jsx
│ │ ├── ProductDetails.jsx
│ │ ├── Pagination.jsx
| | ├── ProductList.jsx
│ │
│ ├── App.jsx
│ ├── index.css
│ └── main.jsx
├── package.json
└── README.md
- Enter a valid product ID in the URL to view details. The ProductDetails component fetches data from the OpenFoodFacts API and displays it in a user-friendly layout.
- The Pagination component allows users to navigate through multiple pages of product data. The current page is highlighted, and clicking on a page number will fetch data for that page.
This app uses the OpenFoodFacts API for fetching product details. You can find more details about the API at OpenFoodFacts API Documentation.
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a new branch:
git checkout -b feature-branch-name
- Make your changes and commit them:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature-branch-name
- Submit a pull request
For questions or feedback, please open an issue on the GitHub repository.
Happy coding!
- Problem: Managing state for the current page, sorting, and category filtering caused inconsistencies in rendering the correct set of products.
- Solution: Utilized React's useState and useEffect hooks to maintain a consistent state across these features. Ensured that state changes triggered appropriate data fetching and updates, allowing smooth transitions between pages and accurate filtering/sorting.
The assignment was completed between September 19 and September 22.