Skip to content

feat: add Back to Top button for better navigation on long pages#222

Open
Vaishnavi22Thakur wants to merge 2 commits into
geturbackend:mainfrom
Vaishnavi22Thakur:feature/back-to-top-button
Open

feat: add Back to Top button for better navigation on long pages#222
Vaishnavi22Thakur wants to merge 2 commits into
geturbackend:mainfrom
Vaishnavi22Thakur:feature/back-to-top-button

Conversation

@Vaishnavi22Thakur
Copy link
Copy Markdown

@Vaishnavi22Thakur Vaishnavi22Thakur commented May 27, 2026

🚀 Pull Request Description

Fixes #219

🛠️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • 🎨 UI/UX improvement (Frontend only)
  • ⚙️ Refactor / Chore

🧪 Testing & Validation

Backend Verification:

  • Not applicable for this change

Frontend Verification:

  • Verified the UI changes on different screen sizes (Responsive)
  • Checked for any console errors in the browser dev tools

Note: Console shows network errors for backend connection (localhost:1234) but these are pre-existing errors unrelated to this change.

📸 Screenshots / Recordings

Before After
Screenshot 2026-05-27 104331 Screenshot 2026-05-27 120833

✅ Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors

📝 Changes Made

  • Created new BackToTop.jsx component in apps/web-dashboard/src/components/Layout/
  • Added <BackToTop /> to MainLayout.jsx for dashboard pages
  • Added <BackToTop /> to LandingPage/index.jsx for the landing page
  • Button appears after scrolling 300px down
  • Smooth scroll back to top on click
  • Matches site's dark theme with teal accent color

Summary by CodeRabbit

  • New Features
    • Added a back-to-top button to the web dashboard and landing page. The circular button automatically becomes visible when you scroll down a page and is positioned in the bottom-right corner as a fixed element. Clicking it smoothly scrolls the entire page back to the top.

Review Change Stack

Signed-off-by: Vaishnavi Thakur <vaaishnavi4713@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@Vaishnavi22Thakur, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 38 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6bccb3b-ec5c-4d1a-9e72-4e4ef993d9b8

📥 Commits

Reviewing files that changed from the base of the PR and between 7391bd4 and d10f283.

📒 Files selected for processing (1)
  • apps/web-dashboard/src/components/Layout/BackToTop.jsx
📝 Walkthrough

Walkthrough

A new BackToTop React component is added that detects when the page scrolls past 300px and displays a fixed button that smoothly scrolls the window to the top. The component is then integrated into both MainLayout and LandingPage to provide consistent back-to-top navigation across the application.

Changes

Back to Top Navigation Feature

Layer / File(s) Summary
BackToTop component implementation
apps/web-dashboard/src/components/Layout/BackToTop.jsx
Introduces the new BackToTop component with scroll-event detection via useEffect, state-based visibility toggling at 300px scroll threshold, fixed-position circular button rendering, and smooth window scroll-to-top on click with proper event-listener cleanup.
Integration into MainLayout and LandingPage
apps/web-dashboard/src/components/Layout/MainLayout.jsx, apps/web-dashboard/src/pages/LandingPage/index.jsx
BackToTop is imported and rendered in both MainLayout and LandingPage to display the back-to-top button in the application's main content areas.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A button to the sky so bright,
Scrolling up with gentle flight,
Past three hundred pixels down,
Now the top is easy found!
Hop along with smoother grace,
Back to where you need to race. ⬆️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: adding a Back to Top button for improved navigation.
Linked Issues check ✅ Passed The PR implementation meets all requirements from issue #219: floating button at bottom-right, appears after 300px scroll, smoothly scrolls to top on click, disappears at top.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the Back to Top button feature. The new component and its integration into MainLayout and LandingPage are within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web-dashboard/src/components/Layout/BackToTop.jsx`:
- Around line 27-30: The icon-only button rendered in BackToTop.jsx (the button
with onClick={handleClick} and content "↑") lacks an explicit accessible name;
add aria-label="Back to Top" to that button element (and the second similar
button instance around line 49) so assistive technologies receive a reliable
name; locate the button elements that use handleClick and add the aria-label
attribute without changing visual text or behavior.
- Around line 4-16: The effect currently registers handleScroll but never runs
it on mount, so BackToTop can remain hidden if the page loads with
window.scrollY > 300; after adding the scroll listener in the useEffect, call
the existing handleScroll() once to initialize visibility (i.e., invoke
handleScroll right after window.addEventListener('scroll', handleScroll)) so
setIsVisible is set correctly on mount; keep the existing cleanup that removes
the listener.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c41caf8f-3d3d-41c6-9082-3e429e518c75

📥 Commits

Reviewing files that changed from the base of the PR and between 6ebd300 and 7391bd4.

📒 Files selected for processing (3)
  • apps/web-dashboard/src/components/Layout/BackToTop.jsx
  • apps/web-dashboard/src/components/Layout/MainLayout.jsx
  • apps/web-dashboard/src/pages/LandingPage/index.jsx

Comment on lines +4 to +16
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Initialize visibility once on mount to avoid stale hidden state.

At Line 4, visibility is only updated after a scroll event. If the page restores at scrollY > 300, the button stays hidden until the user scrolls again. Call handleScroll() once in the effect after registering the listener.

Proposed fix
 useEffect(() => {
     const handleScroll = () => {
         if (window.scrollY > 300) {
             setIsVisible(true);
         } else {
             setIsVisible(false);
         }
     };
     window.addEventListener('scroll', handleScroll);
+    handleScroll();
     return () => {
         window.removeEventListener('scroll', handleScroll);
     };
 }, []);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};
window.addEventListener('scroll', handleScroll);
handleScroll();
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web-dashboard/src/components/Layout/BackToTop.jsx` around lines 4 - 16,
The effect currently registers handleScroll but never runs it on mount, so
BackToTop can remain hidden if the page loads with window.scrollY > 300; after
adding the scroll listener in the useEffect, call the existing handleScroll()
once to initialize visibility (i.e., invoke handleScroll right after
window.addEventListener('scroll', handleScroll)) so setIsVisible is set
correctly on mount; keep the existing cleanup that removes the listener.

Comment thread apps/web-dashboard/src/components/Layout/BackToTop.jsx
Signed-off-by: Vaishnavi Thakur <vaaishnavi4713@gmail.com>
@yash-pouranik
Copy link
Copy Markdown
Collaborator

BRo @coderabbitai
please check

  • feat implemented nicely?
  • code quality?
  • files placed?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== BackToTop.jsx ==="
cat apps/web-dashboard/src/components/Layout/BackToTop.jsx

echo ""
echo "=== MainLayout.jsx ==="
cat apps/web-dashboard/src/components/Layout/MainLayout.jsx

echo ""
echo "=== LandingPage/index.jsx ==="
cat apps/web-dashboard/src/pages/LandingPage/index.jsx

echo ""
echo "=== Layout folder structure ==="
tree apps/web-dashboard/src/components/Layout/ 2>/dev/null || ls -la apps/web-dashboard/src/components/Layout/

Length of output: 58232



PR description image 1 (production at urbackend.bitbros.in): Shows the dark landing page "Build Anything." with three use-case cards — button not visible because the page hasn't been scrolled, which is correct expected behavior.

PR description image 2 (localhost:5173): Shows the dev server with the cyan/teal circular back-to-top button visibly rendered in the bottom-right corner with an upward arrow — feature working correctly.


@yash-pouranik Here's the full breakdown:


✅ Feature — Implemented Correctly

All requirements from issue #219 are met:

Requirement Status
Appears after 300px scroll
Smooth scroll to top on click
Disappears when at the top
Fixed position, bottom-right
Teal accent matches site theme
aria-label + title for accessibility
Cleanup of scroll listener on unmount

✅ File Placement — Correct

BackToTop.jsx lives in apps/web-dashboard/src/components/Layout/ alongside Footer.jsx, Header.jsx, Sidebar.jsx etc. — exactly the right place. Import paths in both MainLayout.jsx and LandingPage/index.jsx are correct.


⚠️ Code Quality — Good, with a few improvements

1. Scroll handler can be simplified (minor)

// Current (verbose)
const handleScroll = () => {
    if (window.scrollY > 300) {
        setIsVisible(true);
    } else {
        setIsVisible(false);
    }
};

// Cleaner
const handleScroll = () => {
    setIsVisible(window.scrollY > 300);
};

2. No debounce/throttle on scroll handler (performance)

Scroll events fire on every pixel of movement — wrapping with a simple throttle is standard practice:

import { useState, useEffect, useCallback } from 'react';

// inside useEffect:
let ticking = false;
const handleScroll = () => {
    if (!ticking) {
        window.requestAnimationFrame(() => {
            setIsVisible(window.scrollY > 300);
            ticking = false;
        });
        ticking = true;
    }
};

3. Use Lucide ArrowUp instead of (consistency)

The entire codebase — including LandingPage/index.jsx — uses lucide-react icons. The Unicode character works but is inconsistent:

import { ArrowUp } from 'lucide-react';

// in the button JSX:
<ArrowUp size={20} strokeWidth={2.5} />

4. No hover effect (UX polish)

All styles are inline, so CSS :hover doesn't apply. You'd need to add a hover state or move to a CSS class:

// Option: add a tiny state
const [isHovered, setIsHovered] = useState(false);
// ...
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
style={{
    // ...existing styles
    transform: isHovered ? 'scale(1.1)' : 'scale(1)',
    transition: 'transform 0.2s ease',
}}

5. Two scroll listeners on LandingPage (minor, acceptable)

LandingPage/index.jsx already has its own scroll listener (for the nav hide/show logic). BackToTop adds a second one. This is fine functionally, but worth knowing — they're independent and don't interfere with each other.


Summary

Check Result
Feature works as per issue #219
File placed correctly
Code structure ✅ Clean
Scroll performance ⚠️ No throttle
Icon consistency (Lucide) ⚠️ Uses Unicode
Hover feedback ⚠️ Missing

Overall solid work — the core feature is well done. The three ⚠️ items above are polish-level improvements, not blockers.

@yash-pouranik
Copy link
Copy Markdown
Collaborator

please fix then will merge
@Vaishnavi22Thakur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add "Back to Top" button for better navigation on long pages

2 participants