Skip to content

c1felode/react-pizza

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ• React Pizza

A simple and elegant pizzeria prototype built with React. Browse through a selection of delicious pizzas, filter by category, customize by size and type, and manage your cart with ease.

πŸ“‹ Table of Contents

✨ Features

  • πŸ• Browse a curated list of pizzas
  • 🏷️ Filter pizzas by category
  • πŸ“ Choose pizza size and type
  • πŸ›’ Add/remove items from your shopping cart
  • πŸ’Ύ Persistent cart using localStorage
  • 🎨 Clean and modern UI
  • πŸ“± Responsive design (in progress)
  • πŸ“Š Redux state management for cart operations

πŸ› οΈ Tech Stack

Frontend

  • React (v19.2.5) - UI library for building interactive components
  • TypeScript (70.2%) - Type-safe JavaScript for better code reliability
  • CSS (25%) - Custom styling with CSS modules
  • Vite (v8.0.10) - Modern bundler for fast development

State Management & Routing

  • Redux Toolkit (v2.11.2) - Simplified Redux state management
  • React Redux (v9.2.0) - React bindings for Redux
  • React Router (v6.30.3) - Client-side routing for navigation

Utilities & APIs

  • Axios (v1.16.0) - HTTP client for API requests
  • Supabase (v2.106.1) - Backend-as-a-Service for database operations
  • React Content Loader (v7.1.2) - Skeleton loading components
  • Vercel Analytics (v2.0.1) - Analytics tracking

Development Tools

  • Vite - Fast module bundler with HMR (Hot Module Replacement)
  • ESLint (v10.2.1) - Code quality and linting
  • React Router DOM (v6.30.3) - DOM-specific routing utilities

πŸ“¦ Installation

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn package manager

Setup

  1. Clone the repository
git clone https://github.com/c1felode/react-pizza.git
cd react-pizza
  1. Install dependencies
npm install
# or
yarn install
  1. Environment Variables (if needed) Create a .env file in the root directory for any API keys or configuration:
VITE_API_URL=your_api_url_here
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_KEY=your_supabase_key

πŸš€ Running the Project

Development Server

Start the development server with hot module replacement:

npm run dev
# or
yarn dev

The application will be available at http://localhost:5173

Build for Production

Create an optimized production build:

npm run build
# or
yarn build

Preview Production Build

Preview the production build locally:

npm run preview
# or
yarn preview

Linting

Check code quality with ESLint:

npm run lint
# or
yarn lint

πŸ“‚ Project Structure

react-pizza/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # Reusable React components
β”‚   β”‚   β”œβ”€β”€ CartItem/        # Individual cart item component
β”‚   β”‚   β”œβ”€β”€ Header/          # Application header
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ pages/               # Page components
β”‚   β”‚   β”œβ”€β”€ Home.tsx         # Main pizzeria page
β”‚   β”‚   β”œβ”€β”€ Cart.tsx         # Shopping cart page
β”‚   β”‚   └── EmptyCart.tsx    # Empty cart message
β”‚   β”œβ”€β”€ redux/               # Redux store and slices
β”‚   β”‚   β”œβ”€β”€ slices/          # Redux action creators
β”‚   β”‚   β”‚   └── cartSlice.ts # Cart state management
β”‚   β”‚   └── store.ts         # Redux store configuration
β”‚   β”œβ”€β”€ types/               # TypeScript type definitions
β”‚   β”‚   β”œβ”€β”€ types.ts         # General types
β”‚   β”‚   └── redux.ts         # Redux state types
β”‚   β”œβ”€β”€ App.tsx              # Root application component
β”‚   β”œβ”€β”€ App.css              # Global styles
β”‚   β”œβ”€β”€ index.css            # Root styles
β”‚   └── main.tsx             # React DOM render entry point
β”œβ”€β”€ index.html               # HTML template
β”œβ”€β”€ package.json             # Project dependencies
β”œβ”€β”€ vite.config.ts           # Vite configuration
β”œβ”€β”€ eslint.config.js         # ESLint configuration
└── tsconfig.json            # TypeScript configuration

πŸ’‘ Code Explanations

1. App.tsx - Application Router

The main component sets up routing and conditional rendering for the cart:

// Routes between Home and Cart pages
// Shows EmptyCart component when cart has no items
// Shows Cart component when items are in cart
<Routes>
  <Route path='/' element={<Home />} />
  <Route path='/cart' element={items.length > 0 ? <Cart /> : <EmptyCart />} />
</Routes>

2. Redux Store - State Management

Redux manages global state for:

  • Pizza Items: List of available pizzas with loading states
  • Filters: Category and sort preferences
  • Cart: Items, total price, and item count

Benefits: Centralized state management, easy debugging, predictable state updates

3. cartSlice.ts - Cart Logic

Handles all cart operations:

  • addItem: Adds pizza to cart or increments count if already present
  • minusItem: Decreases pizza quantity (won't go below 1)
  • removeItem: Removes pizza completely from cart
  • clearCart: Empties entire cart
  • localStorage Integration: Persists cart data across browser sessions
const updateCartStorage = (state: ICartState) => {
    state.totalPrice = state.items.reduce((sum, obj) => (obj.price * obj.count) + sum, 0);
    state.totalCount = state.items.reduce((sum, obj) => obj.count + sum, 0);
    localStorage.setItem('cart', JSON.stringify(state.items));
};

4. CartItem Component

Individual item in cart with controls:

  • Displays pizza image, title, size, and type
  • Plus/minus buttons to adjust quantity
  • Delete button to remove item
  • Dispatches Redux actions for state updates

5. React Router Integration

Uses React Router v6 for:

  • Page navigation without page reloads
  • URL-based state management
  • Link components for navigation

6. TypeScript Types

Type safety throughout the app:

  • TCartItem: Defines pizza cart item structure
  • IPizzaState: Redux pizza state interface
  • ICartState: Redux cart state interface
  • IRootState: Complete Redux state shape

πŸ”„ State Flow Diagram

User Action (Click Add/Remove)
    ↓
Component dispatches Redux Action
    ↓
Reducer updates state
    ↓
Component receives updated state via useSelector
    ↓
Component re-renders with new data
    ↓
localStorage is synced automatically

🚧 Future Improvements

  • Responsive mobile design
  • Advanced styling and animations
  • More features and enhancements
  • Payment integration
  • Order tracking
  • User authentication
  • Admin dashboard

πŸ“ License

ISC

🀝 Contributing

Feel free to fork this project and submit pull requests for any improvements!

πŸ“ž Support

For issues and questions, please open an issue on GitHub Issues


Happy coding! πŸš€ Enjoy building your pizzeria!

About

Simple Prototype of pizzeria called React Pizza Here you'll find a list of pizzas with categories.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors