Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved the scroll to top button #3616

Closed
wants to merge 3 commits into from

Conversation

hkv24
Copy link
Contributor

@hkv24 hkv24 commented Jan 28, 2025

Description

  • Changed the <img> tag with <Image /> component to enhance the performance which will be done by Next JS automatically.
  • Fixed the spacing of the scroll to top button.
  • Also changed the Svg which is royalty free svg taken from https://www.svgrepo.com/svg/195821/up-arrow?edit=true .

Resolves #3614

Summary by CodeRabbit

  • Style
    • Updated scroll button positioning and layout
    • Replaced standard image tag with Next.js optimized Image component
    • Enhanced button styling with improved alignment and sizing

Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request modifies the ScrollButton component in components/buttons/ScrollButton.tsx, focusing on improving the scroll-to-top button's design and performance. The changes include replacing the <img> tag with Next.js's <Image> component, adjusting CSS classes for better layout and alignment, and modifying the button's vertical positioning. These modifications aim to create a more elegant and optimized scroll button implementation.

Changes

File Change Summary
components/buttons/ScrollButton.tsx - Added Image import from 'next/image'
- Changed bottom positioning from bottom-14 to bottom-4
- Added CSS classes: flex, size-10, items-center, justify-center
- Replaced <img> with <Image> component and set height/width to 30

Assessment against linked issues

Objective Addressed Explanation
Replace <img> with Next.js <Image>
Improve button design and spacing
Make scroll button more elegant

Possibly related issues

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • magicmatatjahu
  • devilkiller-ag
  • akshatnema
  • sambhavgupta0705
  • asyncapi-bot-eve
  • Mayaleeeee
  • anshgoyalevil

Poem

🐰 A scroll button's tale, sleek and bright,
Hopping up with Next.js might!
From img to Image, clean and neat,
A rabbit's design can't be beat!
Positioning perfect, classes just right,
Our scroll button now takes flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for asyncapi-website failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit e019825
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67992a69f172b50008d4d408

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (99512bf) to head (e019825).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3616   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines          732       732           
=========================================
  Hits           732       732           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
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: 0

🔭 Outside diff range comments (1)
components/buttons/ScrollButton.tsx (1)

Line range hint 13-19: Add cleanup for scroll event listener.

The scroll event listener is not cleaned up when the component unmounts, which could lead to memory leaks. Add a cleanup function in the useEffect hook.

   useEffect(() => {
-    window.addEventListener('scroll', () => {
+    const handleScroll = () => {
       if (window.scrollY > 150) {
         setBackToTopButton(true);
       } else {
         setBackToTopButton(false);
       }
-    });
+    };
+    
+    window.addEventListener('scroll', handleScroll);
+    return () => window.removeEventListener('scroll', handleScroll);
   }, []);
🧹 Nitpick comments (1)
components/buttons/ScrollButton.tsx (1)

36-36: Consider optimizing the Image component configuration.

While the Image component implementation is correct, consider these optimizations:

  1. Since you're using an SVG, you might not need the Next.js Image component. SVGs are already optimized vector graphics.
  2. If you keep the Image component, consider adding loading="lazy" since this is below-the-fold content.
-          <Image src={scrollImage} alt='scroll to top' height={30} width={30} />
+          <img src={scrollImage} alt='scroll to top' className="h-[30px] w-[30px]" />

Or if you prefer keeping the Image component:

-          <Image src={scrollImage} alt='scroll to top' height={30} width={30} />
+          <Image 
+            src={scrollImage} 
+            alt='scroll to top' 
+            height={30} 
+            width={30}
+            loading="lazy"
+          />
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99512bf and e019825.

⛔ Files ignored due to path filters (1)
  • public/img/loaders/scroll.svg is excluded by !**/*.svg
📒 Files selected for processing (1)
  • components/buttons/ScrollButton.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 180000ms (1)
  • GitHub Check: Lighthouse CI
🔇 Additional comments (2)
components/buttons/ScrollButton.tsx (2)

1-1: LGTM! Good use of Next.js Image component.

Using next/image instead of the standard img tag will provide automatic image optimization, lazy loading, and prevent Cumulative Layout Shift (CLS).


30-35: Verify mobile compatibility with reduced bottom spacing.

The button's position has been moved closer to the bottom (from bottom-14 to bottom-4). While the layout improvements with flex and sizing look good, please verify that:

  1. The button doesn't overlap with mobile browser navigation bars
  2. The button remains easily tappable on mobile devices (consider touch target size guidelines)
✅ Verification successful

Mobile compatibility verified - implementation is safe ✅

The scroll button implementation:

  • Has sufficient spacing (16px) from bottom edge
  • Uses appropriate z-index layering to prevent conflicts
  • Meets touch target size requirements (40x40px)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any mobile-specific styles or media queries that might affect the button's positioning
rg -g '*.css' -g '*.scss' -g '*.tsx' -g '*.jsx' 'bottom-\d+.*mobile|@media.*bottom-\d+'

Length of output: 89


Script:

#!/bin/bash
# Search for mobile navigation components and bottom-fixed elements
echo "=== Searching for mobile navigation components ==="
rg -g '*.tsx' -g '*.jsx' 'nav|navbar|navigation' -A 5 -B 5

echo "=== Searching for fixed positioning and z-index usage ==="
rg -g '*.tsx' -g '*.jsx' 'fixed.*bottom|z-\d+.*fixed|bottom.*z-\d+'

echo "=== Checking viewport-related utilities ==="
rg -g '*.tsx' -g '*.jsx' '@media|useMediaQuery|screen.*min-width|screen.*max-width'

Length of output: 41148

@sambhavgupta0705
Copy link
Member

closing this as not relevant

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.

2 participants