Skip to content

Commit fe92004

Browse files
feat(frontend): updated
1 parent 4168b6d commit fe92004

File tree

7 files changed

+1047
-1
lines changed

7 files changed

+1047
-1
lines changed

frontend/package-lock.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"cmdk": "^1.1.1",
4646
"date-fns": "^3.6.0",
4747
"embla-carousel-react": "^8.6.0",
48+
"framer-motion": "^12.23.24",
4849
"input-otp": "^1.4.2",
4950
"lucide-react": "^0.462.0",
5051
"next-themes": "^0.3.0",

frontend/src/App.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import Browse from "./pages/Browse";
99
import Sell from "./pages/Sell";
1010
import ProductDetailsPage from "./pages/ProductDetail";
1111
import Navbar from "./components/Navbar";
12+
import { CartProvider } from "./components/CartContext.jsx";
13+
import Home from "./pages/Home.jsx";
14+
import Cart from "./pages/Cart.jsx";
15+
import Payment from "./pages/Payment";
1216
const queryClient = new QueryClient();
1317

1418
const App = () => (
@@ -19,15 +23,21 @@ const App = () => (
1923
<BrowserRouter>
2024
<Navbar />
2125
<div className="pt-[50px]">
22-
26+
<CartProvider>
27+
2328
<Routes>
2429
<Route path="/" element={<Index />} />
30+
2531
<Route path="/signup" element={<SignUp />} />
2632
<Route path="/signin" element={<SignIn />} />
2733
<Route path="/browse" element={<Browse />} />
2834
<Route path="/product/:id" element={<ProductDetailsPage />} />
35+
<Route path="/CartHome" element={<Home />} />
36+
<Route path="/cart" element={<Cart />} />
37+
<Route path="/payment" element={<Payment />} />
2938
<Route path="/sell" element={<Sell />} />
3039
</Routes>
40+
</CartProvider>
3141
</div>
3242
</BrowserRouter>
3343
</TooltipProvider>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { createContext, useReducer, useEffect, useState } from "react";
2+
3+
export const CartContext = createContext();
4+
5+
const initialState = {
6+
cart: JSON.parse(localStorage.getItem("cart")) || [],
7+
};
8+
9+
const reducer = (state, action) => {
10+
switch (action.type) {
11+
case "ADD_ITEM":
12+
return { ...state, cart: [...state.cart, action.payload] };
13+
case "REMOVE_ITEM":
14+
return {
15+
...state,
16+
cart: state.cart.filter((_, i) => i !== action.payload),
17+
};
18+
case "CLEAR_CART":
19+
return { ...state, cart: [] };
20+
default:
21+
return state;
22+
}
23+
};
24+
25+
export const CartProvider = ({ children }) => {
26+
const [state, dispatch] = useReducer(reducer, initialState);
27+
const [notification, setNotification] = useState(null);
28+
29+
useEffect(() => {
30+
localStorage.setItem("cart", JSON.stringify(state.cart));
31+
}, [state.cart]);
32+
33+
return (
34+
<CartContext.Provider value={{ state, dispatch, notification, setNotification }}>
35+
{children}
36+
</CartContext.Provider>
37+
);
38+
};

0 commit comments

Comments
 (0)