Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Todo from "./pages/Todo";
import Login from "./pages/Login";
import Register from "./pages/Register";
import ProtectedRoute from "./components/ProtectedRoute";
import ScrollToTop from "./components/ScrollToTop";

const App = () => {
return (
Expand All @@ -31,6 +32,7 @@ const App = () => {
{/* Navbar is hidden on login/register via CSS β€” it checks the route */}
<NavbarWrapper />
<ScrollToTop />
<ScrollToTop />
<Routes>
{/* ── Public routes ── */}
<Route path="/login" element={<Login />} />
Expand Down
25 changes: 25 additions & 0 deletions client/src/components/ScrollToTop.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.scroll-to-top-btn {
position: fixed;
bottom: 30px;
right: 30px;
width: 45px;
height: 45px;
border-radius: 50%;
background-color: #4f46e5;
color: #ffffff;
border: none;
font-size: 20px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
transition: opacity 0.3s ease, transform 0.2s ease;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
}

.scroll-to-top-btn:hover {
background-color: #4338ca;
transform: translateY(-3px);
}
43 changes: 43 additions & 0 deletions client/src/components/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState, useEffect } from "react";
import "./ScrollToTop.css";

const ScrollToTop = () => {
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
const toggleVisibility = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};

window.addEventListener("scroll", toggleVisibility);
return () => window.removeEventListener("scroll", toggleVisibility);
}, []);

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

return (
<>
{isVisible && (
<button
className="scroll-to-top-btn"
onClick={scrollToTop}
aria-label="Scroll to top"
title="Back to top"
>
↑
</button>
)}
</>
);
};

export default ScrollToTop;