From b7e2f105edfc099280d5fc1c34afcae147a181dd Mon Sep 17 00:00:00 2001 From: Shashank RM Date: Mon, 8 Sep 2025 18:21:44 +0530 Subject: [PATCH 1/4] feat: add reusable BackButton component for navigation --- frontend/src/Components/ui/BackButton.jsx | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 frontend/src/Components/ui/BackButton.jsx diff --git a/frontend/src/Components/ui/BackButton.jsx b/frontend/src/Components/ui/BackButton.jsx new file mode 100644 index 0000000..7e2dd6e --- /dev/null +++ b/frontend/src/Components/ui/BackButton.jsx @@ -0,0 +1,33 @@ +import { useNavigate } from 'react-router-dom'; +import { Button } from '../ui/button'; +import { ArrowLeft } from 'lucide-react'; + +/** + * Reusable BackButton component for navigation. + * Navigates to previous page or dashboard if no history. + * + * Usage: + */ +export default function BackButton({ to = '/dashboard', className = '' }) { + const navigate = useNavigate(); + + function handleBack() { + if (window.history.length > 2) { + navigate(-1); + } else { + navigate(to); + } + } + + return ( + + ); +} From aae4db5e1cea2165d8b6144932263d5b810c74a7 Mon Sep 17 00:00:00 2001 From: Shashank RM Date: Mon, 8 Sep 2025 18:24:21 +0530 Subject: [PATCH 2/4] feat: add PageWithBackButton layout to show back button on all non-home pages --- .../Components/layout/PageWithBackButton.jsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 frontend/src/Components/layout/PageWithBackButton.jsx diff --git a/frontend/src/Components/layout/PageWithBackButton.jsx b/frontend/src/Components/layout/PageWithBackButton.jsx new file mode 100644 index 0000000..6e3a48b --- /dev/null +++ b/frontend/src/Components/layout/PageWithBackButton.jsx @@ -0,0 +1,20 @@ +import React from "react"; +import { useLocation } from "react-router-dom"; +import BackButton from "../ui/BackButton"; + +/** + * Layout wrapper that adds a back button to all pages except home ("/"). + * Usage: + */ +export default function PageWithBackButton({ children }) { + const location = useLocation(); + // Hide back button on home page + const hideBack = location.pathname === "/"; + + return ( + <> + {!hideBack && } + {children} + + ); +} From 58d1901a79e26a04c5da2d4951599826a909d5cc Mon Sep 17 00:00:00 2001 From: Shashank RM Date: Mon, 8 Sep 2025 18:25:10 +0530 Subject: [PATCH 3/4] refactor: wrap all non-home routes with PageWithBackButton for global back button support --- frontend/src/App.jsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 12ef62a..dc29d69 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -11,11 +11,13 @@ import Footer from "./Components/footer"; import ScrollRevealWrapper from "./Components/ui/ScrollRevealWrapper"; import Loader from "./Components/ui/Loader"; // ✅ Import the Loader + import Login from "./Components/auth/Login"; import Register from "./Components/auth/Register"; import Profile from "./Components/profile/Profile"; import ProtectedRoute from "./Components/auth/ProtectedRoute"; import Dashboard from "./Components/Dashboard"; +import PageWithBackButton from "./Components/layout/PageWithBackButton"; // Home component that contains the main landing page content @@ -114,18 +116,19 @@ function App() { return ( } /> - } /> - } /> - + } /> + } /> - - + + + + + } /> - } /> + } /> ); } From 9ba124644375f65204870330abcca9fc68510a0b Mon Sep 17 00:00:00 2001 From: Shashank RM Date: Mon, 8 Sep 2025 18:27:28 +0530 Subject: [PATCH 4/4] refactor: remove redundant BackButton import and usage (now handled globally) --- frontend/src/Components/profile/Profile.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/Components/profile/Profile.jsx b/frontend/src/Components/profile/Profile.jsx index a8af372..9c6222c 100644 --- a/frontend/src/Components/profile/Profile.jsx +++ b/frontend/src/Components/profile/Profile.jsx @@ -294,6 +294,7 @@ const Profile = () => { return (
+ {/* Back Button handled globally by layout */} {/* Navbar */}