From f783590844a10a1318036d9d18b18d6f153cfe05 Mon Sep 17 00:00:00 2001 From: bender Date: Sat, 13 Jun 2026 02:40:43 +0000 Subject: [PATCH 1/3] Add src/app/cartContext.tsx --- src/app/cartContext.tsx | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/app/cartContext.tsx diff --git a/src/app/cartContext.tsx b/src/app/cartContext.tsx new file mode 100644 index 0000000..39b67af --- /dev/null +++ b/src/app/cartContext.tsx @@ -0,0 +1,87 @@ +"use client"; + +import React, { createContext, useContext, useState, useEffect } from "react"; + +interface CartItem { + id: string; + name: string; + price: number; + imageSrc: string; + quantity: number; +} + +interface CartContextType { + cartItems: CartItem[]; + addToCart: (product: { id: string; name: string; price: string; imageSrc: string; imageAlt?: string }) => void; + removeFromCart: (id: string) => void; + updateQuantity: (id: string, quantity: number) => void; + clearCart: () => void; + totalPrice: number; +} + +const CartContext = createContext(undefined); + +export const CartProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { + const [cartItems, setCartItems] = useState([]); + + useEffect(() => { + // Load cart from localStorage on mount + if (typeof window !== "undefined") { + const storedCart = localStorage.getItem("shopwel_cart"); + if (storedCart) { + setCartItems(JSON.parse(storedCart)); + } + } + }, []); + + useEffect(() => { + // Save cart to localStorage whenever it changes + if (typeof window !== "undefined") { + localStorage.setItem("shopwel_cart", JSON.stringify(cartItems)); + } + }, [cartItems]); + + const addToCart = (product: { id: string; name: string; price: string; imageSrc: string; imageAlt?: string }) => { + setCartItems((prevItems) => { + const itemExists = prevItems.find((item) => item.id === product.id); + if (itemExists) { + return prevItems.map((item) => + item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item + ); + } else { + const priceValue = parseFloat(product.price.replace("₹", "").replace("/kg", "").replace("/L", "")); + return [...prevItems, { ...product, price: priceValue, quantity: 1 }]; + } + }); + }; + + const removeFromCart = (id: string) => { + setCartItems((prevItems) => prevItems.filter((item) => item.id !== id)); + }; + + const updateQuantity = (id: string, quantity: number) => { + setCartItems((prevItems) => + prevItems.map((item) => (item.id === id ? { ...item, quantity: Math.max(1, quantity) } : item)) + ); + }; + + const clearCart = () => { + setCartItems([]); + }; + + const totalPrice = cartItems.reduce((total, item) => total + item.price * item.quantity, 0); + + return ( + + {children} + + ); +}; + +export const useCart = () => { + const context = useContext(CartContext); + if (context === undefined) { + throw new Error("useCart must be used within a CartProvider"); + } + return context; +}; -- 2.49.1 From f3cece70195f35853343e10f0d3f6b996d0d147f Mon Sep 17 00:00:00 2001 From: bender Date: Sat, 13 Jun 2026 02:40:44 +0000 Subject: [PATCH 2/3] Update src/app/page.tsx --- src/app/page.tsx | 272 +++++++++++------------------------------------ 1 file changed, 64 insertions(+), 208 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 27677bd..f081e60 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -14,6 +14,23 @@ import SocialProofOne from '@/components/sections/socialProof/SocialProofOne'; import TestimonialCardOne from '@/components/sections/testimonial/TestimonialCardOne'; export default function LandingPage() { + const updatedNavItems = [ + { + name: "Home", id: "#home"}, + { + name: "About", id: "#about"}, + { + name: "Products", id: "#products"}, + { + name: "Orders", id: "/order-details"}, + { + name: "Testimonials", id: "#testimonials"}, + { + name: "FAQs", id: "#faqs"}, + { + name: "Contact", id: "#contact"}, + ]; + return (
@@ -278,25 +174,13 @@ export default function LandingPage() { useInvertedBackground={true} faqs={[ { - id: "faq1", - title: "What are your operating hours?", - content: "Shopwel Mart is open from 8:00 AM to 9:00 PM, Monday through Sunday, for your convenience.", - }, + id: "faq1", title: "What are your operating hours?", content: "Shopwel Mart is open from 8:00 AM to 9:00 PM, Monday through Sunday, for your convenience."}, { - id: "faq2", - title: "Do you offer home delivery?", - content: "Currently, we do not offer home delivery, but we are working on introducing this service soon. Please visit our store for your shopping needs.", - }, + id: "faq2", title: "Do you offer home delivery?", content: "Currently, we do not offer home delivery, but we are working on introducing this service soon. Please visit our store for your shopping needs."}, { - id: "faq3", - title: "What is your return policy?", - content: "We accept returns of unused and unopened items within 7 days of purchase, with a valid receipt. Fresh produce returns must be made within 24 hours.", - }, + id: "faq3", title: "What is your return policy?", content: "We accept returns of unused and unopened items within 7 days of purchase, with a valid receipt. Fresh produce returns must be made within 24 hours."}, { - id: "faq4", - title: "Are there any special discounts for bulk purchases?", - content: "Yes, we offer special discounts for bulk purchases on select items. Please speak to our store manager for more details on available offers.", - }, + id: "faq4", title: "Are there any special discounts for bulk purchases?", content: "Yes, we offer special discounts for bulk purchases on select items. Please speak to our store manager for more details on available offers."}, ]} title="Frequently Asked Questions" description="Find quick answers to common questions about shopping at Shopwel Mart, from our operating hours to return policies." @@ -308,14 +192,11 @@ export default function LandingPage() {
@@ -325,62 +206,37 @@ export default function LandingPage() { logoText="Shopwel Mart" columns={[ { - title: "Categories", - items: [ + title: "Categories", items: [ { - label: "Fresh Produce", - href: "#products", - }, + label: "Fresh Produce", href: "#products"}, { - label: "Groceries", - href: "#products", - }, + label: "Groceries", href: "#products"}, { - label: "Household", - href: "#products", - }, + label: "Household", href: "#products"}, { - label: "Dairy & Bakery", - href: "#products", - }, + label: "Dairy & Bakery", href: "#products"}, ], }, { - title: "About Us", - items: [ + title: "About Us", items: [ { - label: "Our Story", - href: "#about", - }, + label: "Our Story", href: "#about"}, { - label: "Why Shopwel", - href: "#features", - }, + label: "Why Shopwel", href: "#features"}, { - label: "Customer Reviews", - href: "#testimonials", - }, + label: "Customer Reviews", href: "#testimonials"}, ], }, { - title: "Connect", - items: [ + title: "Connect", items: [ { - label: "Location", - href: "#contact", - }, + label: "Location", href: "#contact"}, { - label: "FAQs", - href: "#faqs", - }, + label: "FAQs", href: "#faqs"}, { - label: "Privacy Policy", - href: "#", - }, + label: "Privacy Policy", href: "#"}, { - label: "Terms of Service", - href: "#", - }, + label: "Terms of Service", href: "#"}, ], }, ]} @@ -390,4 +246,4 @@ export default function LandingPage() {
); -} +} \ No newline at end of file -- 2.49.1 From 71ff05fda48998b5e9ce14c477e896157d8419d8 Mon Sep 17 00:00:00 2001 From: bender Date: Sat, 13 Jun 2026 02:44:08 +0000 Subject: [PATCH 3/3] Update src/app/cartContext.tsx --- src/app/cartContext.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/app/cartContext.tsx b/src/app/cartContext.tsx index 39b67af..d3e97df 100644 --- a/src/app/cartContext.tsx +++ b/src/app/cartContext.tsx @@ -22,17 +22,16 @@ interface CartContextType { const CartContext = createContext(undefined); export const CartProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { - const [cartItems, setCartItems] = useState([]); - - useEffect(() => { - // Load cart from localStorage on mount + const [cartItems, setCartItems] = useState(() => { + // Load cart from localStorage on initial render if (typeof window !== "undefined") { const storedCart = localStorage.getItem("shopwel_cart"); if (storedCart) { - setCartItems(JSON.parse(storedCart)); + return JSON.parse(storedCart); } } - }, []); + return []; + }); useEffect(() => { // Save cart to localStorage whenever it changes -- 2.49.1