Skip to content

feat: implement hooks api with test - #1

Open
saumya-cw wants to merge 2 commits into
masterfrom
feature/practice-branch
Open

saumya-cw wants to merge 2 commits into
masterfrom
feature/practice-branch

Conversation

@saumya-cw

Copy link
Copy Markdown
Owner

What This PR Does

Introduces a Food Nutrition Explorer feature with API integration, TypeScript types, and a responsive UI for checking product nutrition data.

Implements a complete flow for fetching, displaying, and toggling food nutrition information with clean architecture and strong type safety.


Added Components & Services

  • FoodLanding Page
    Main landing page with a toggle for displaying nutrition data

  • FoodApi Service
    Axios-based service for fetching product data from OpenFoodFacts

  • useFood Hook
    Custom hook responsible for:

    • fetching nutrition data
    • managing loading and error states
  • Food Types
    TypeScript interfaces for:

    • API responses
    • product and nutriment data
  • FoodApi Tests
    Unit tests for the API service with mocked:

    • success cases
    • failure cases
    • error scenarios

Implementation Details

  • Built using:
    • TypeScript
    • Axios
    • Tailwind CSS
  • Mobile-first, responsive UI design
  • Clear separation of concerns:
    • services – API communication
    • hooks – state and data management
    • types – TypeScript interfaces
    • UI components – presentation only
  • Introduces services and hooks folders for better project organization

App Integration Details

The Food Nutrition Explorer is integrated into the main app layout with the following user flow:

Home View

  • Displays “Check Product Nutrition” button

Nutrition View

  • Displays:
    • product name
    • brand(s)
    • nutriment information
  • Includes “Return to Home” button to toggle back

Responsive Design

  • Optimized for mobile and desktop devices
  • Seamless layout adaptation across breakpoints

Manual Steps for Reviewer

Start the Development Server

npm run dev

Verify the Following

  • Application starts successfully
  • No TypeScript errors in the terminal
  • No console errors in the browser
  • Home page displays “Check Product Nutrition” button
  • Clicking the button reveals nutrition data on the same page
  • “Return to Home” button switches back to home view
  • Responsive layout works on mobile and desktop
  • API data loads correctly (verify via console logs if needed)

Definition of Done (DoD)

  • Food nutrition feature implemented using TypeScript and Axios
  • Mobile-first responsive design implemented
  • API integration includes:
    • error handling
  • Unit tests added for the API service

Testing

  • Application loads successfully
  • No console errors on initial render
  • API calls work and nutrition data displays correctly
  • Toggle between Home and Nutrition views works as expected
  • Unit tests pass

@saumya-cw

Copy link
Copy Markdown
Owner Author

@cw-pr-agent review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant