From 1fae2204d06319de832148caf7ad2856e8d03e9a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 13 Mar 2026 01:53:04 +0000 Subject: [PATCH] Auto commit: 2026-03-13T01:53:04.187Z --- frontend/src/App.tsx | 25 +++++++++++++++---------- frontend/src/AuthContext.tsx | 28 ++++++++++++++++++++++++++++ frontend/src/CartPage.tsx | 33 +++++++++++++++++++++++++++++++++ frontend/src/Header.tsx | 18 +++++++++++++++--- frontend/src/LoginPage.tsx | 15 ++++++++++++--- 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 frontend/src/AuthContext.tsx create mode 100644 frontend/src/CartPage.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 2335416..e5ba036 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -3,21 +3,26 @@ import Header from './Header'; import LoginPage from './LoginPage'; import ProductList from './ProductList'; import ProductDetail from './ProductDetail'; +import CartPage from './CartPage'; import { CartProvider } from './CartContext'; +import { AuthProvider } from './AuthContext'; function App() { return ( - -
-
- - } /> - } /> - } /> - -
- + + +
+
+ + } /> + } /> + } /> + } /> + +
+ + ) } diff --git a/frontend/src/AuthContext.tsx b/frontend/src/AuthContext.tsx new file mode 100644 index 0000000..16d2bba --- /dev/null +++ b/frontend/src/AuthContext.tsx @@ -0,0 +1,28 @@ +import React, { createContext, useContext, useState, ReactNode } from 'react'; + +interface AuthContextType { + isAuthenticated: boolean; + login: () => void; + logout: () => void; +} + +const AuthContext = createContext(undefined); + +export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => { + const [isAuthenticated, setIsAuthenticated] = useState(false); + + const login = () => setIsAuthenticated(true); + const logout = () => setIsAuthenticated(false); + + return ( + + {children} + + ); +}; + +export const useAuth = () => { + const context = useContext(AuthContext); + if (!context) throw new Error('useAuth must be used within AuthProvider'); + return context; +}; diff --git a/frontend/src/CartPage.tsx b/frontend/src/CartPage.tsx new file mode 100644 index 0000000..e01fb27 --- /dev/null +++ b/frontend/src/CartPage.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { useCart } from './CartContext'; + +const CartPage: React.FC = () => { + const { cart } = useCart(); + + const total = cart.reduce((sum, item) => sum + item.price, 0); + + return ( +
+

Your Shopping Cart

+ {cart.length === 0 ? ( +

Your cart is empty.

+ ) : ( +
+
    + {cart.map((item, index) => ( +
  • + {item.name} + ${item.price.toFixed(2)} +
  • + ))} +
+
+ Total: ${total.toFixed(2)} +
+
+ )} +
+ ); +}; + +export default CartPage; diff --git a/frontend/src/Header.tsx b/frontend/src/Header.tsx index 756a1d3..54e6774 100644 --- a/frontend/src/Header.tsx +++ b/frontend/src/Header.tsx @@ -1,10 +1,22 @@ +import { Link } from 'react-router-dom'; +import { useAuth } from './AuthContext'; + export default function Header() { + const { isAuthenticated, logout } = useAuth(); + return (
-

MyApp

+

+ MyApp +

); diff --git a/frontend/src/LoginPage.tsx b/frontend/src/LoginPage.tsx index 6b08657..9105e62 100644 --- a/frontend/src/LoginPage.tsx +++ b/frontend/src/LoginPage.tsx @@ -1,13 +1,22 @@ import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useAuth } from './AuthContext'; export default function LoginPage() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); + const { login } = useAuth(); + const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - console.log('Login attempt:', { username, password }); - // TODO: Implement actual JWT authentication logic here + // Simulate login + if (username === 'admin' && password === 'password') { + login(); + navigate('/'); + } else { + alert('Invalid credentials'); + } }; return ( @@ -45,4 +54,4 @@ export default function LoginPage() { ); -} +} \ No newline at end of file