Conversation
…rdodiya#268) - Created CartContext with localStorage persistence for cart items - CartProvider wraps CustomerLayout so cart is available on all customer pages - Added CartDrawer component with item list, quantity controls, remove, and clear - Added cart button with badge in Navigation showing item count - Added "Add to Cart" buttons on menu items in MenuSection - Cart state auto-saves to localStorage on every change - On page load, cart is restored from localStorage
There was a problem hiding this comment.
🟡 Changes recommended
There is a persistence-breaking bug with falsy foodId values (e.g., 0) and a couple of user-facing issues (currency inconsistency and missing accessible labels) that should be fixed before merge.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces a customer cart feature backed by a new CartContext that persists cart contents to localStorage, allowing the cart to survive page refreshes (addressing issue #268).
Changes:
- Added a
CartProvider/useCartcontext withlocalStorageload/save behavior. - Introduced a slide-in
CartDrawerUI and wired it into the restaurant menu page via a cart button inNavigation. - Added “Add to Cart” actions in
MenuSectionand wrapped customer routes withCartProviderinCustomerLayout.
File summaries
| File | Description |
|---|---|
| RestroHub-FrontEnd/src/pages/customer/RestaurantMenu.jsx | Adds cart drawer open/close state and wires Navigation cart button to open the drawer. |
| RestroHub-FrontEnd/src/layouts/CustomerLayout.jsx | Wraps customer pages with CartProvider so cart state is available throughout the customer area. |
| RestroHub-FrontEnd/src/context/CartContext.jsx | Implements persisted cart state, cart operations, and derived totals/counts. |
| RestroHub-FrontEnd/src/components/customer/Navigation.jsx | Adds cart button with badge showing item count and triggers drawer open via callback prop. |
| RestroHub-FrontEnd/src/components/customer/MenuSection.jsx | Adds “Add to Cart” button per menu item and uses cart context to add items. |
| RestroHub-FrontEnd/src/components/customer/CartDrawer.jsx | New drawer UI for viewing/updating/removing items and clearing the cart. |
Review details
Suppressed comments (1)
RestroHub-FrontEnd/src/components/customer/MenuSection.jsx:74
- Menu prices are rendered with a
$prefix here, but the rest of the app (including the new cart drawer) uses₹, leading to inconsistent currency display for the same items.
<p className="menu-item-price font-heading">
{item.price === 'varies' ? item.price : `$${item.price}`}
</p>
- Files reviewed: 6/6 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const parsed = JSON.parse(raw); | ||
| if (!Array.isArray(parsed)) return []; | ||
| return parsed.filter(item => item && item.foodId); | ||
| } catch { |
| <button | ||
| onClick={() => addItem({ | ||
| foodId: item.foodId || item.id || index, | ||
| name: item.name, | ||
| price: item.price === 'varies' ? 0 : parseFloat(item.price) || 0, | ||
| imageUrl: item.imageUrl || '', | ||
| isVeg: item.isVeg ?? true, | ||
| })} |
| <button | ||
| onClick={() => removeItem(item.foodId)} | ||
| style={{ |
| <button | ||
| onClick={onClose} | ||
| style={{ |
|
Hi @Siddh2024 , |
Description
Fixes #268
The cart state was previously held only in memory and lost on page refresh. This PR adds localStorage persistence so cart items survive page reloads.
Changes Made
CartContext (src/context/CartContext.jsx)
CartDrawer (src/components/customer/CartDrawer.jsx)
Navigation & MenuSection Updates
Testing