-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
fix: navigation to correct heading in tools section #2790
Changes from 2 commits
dca670b
6b5beb0
5a5d4eb
8fa5582
24320af
7a6cd6d
5e08246
e039f26
020e4ce
9e82491
53715db
7dcfb6f
6fd2e87
66fe5de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,25 @@ | ||||||||
import ToolsCard from './ToolsCard'; | ||||||||
import Heading from '../typography/Heading' | ||||||||
import { useRef, useEffect } from 'react'; | ||||||||
import Paragraph from '../typography/Paragraph' | ||||||||
export default function toolsList({ toolsData }) { | ||||||||
const categoryRefs = useRef({}); | ||||||||
|
||||||||
useEffect(() => { | ||||||||
const hash = window.location.hash; | ||||||||
if (hash) { | ||||||||
Vishal2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
const decodedHash = decodeURIComponent(hash.slice(1)); | ||||||||
const categoryRef = categoryRefs.current[decodedHash]; | ||||||||
Vishal2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
if (categoryRef) { | ||||||||
categoryRef.scrollIntoView({ behavior: 'smooth', block: 'start' }); | ||||||||
} | ||||||||
} | ||||||||
}, []); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What changes to add here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just add a newline at the end of the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clean code rules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done Sir |
||||||||
return ( | ||||||||
<div className="" data-testid="ToolsList-main" > | ||||||||
{Object.keys(toolsData).map((categoryName, index) => { | ||||||||
if(toolsData[categoryName].toolsList.length > 0) return ( | ||||||||
<div className='my-8' key={index} id={categoryName}> | ||||||||
<div className='my-8' key={index} id={categoryName} ref={el => categoryRefs.current[categoryName] = el}> | ||||||||
<Heading typeStyle='heading-md-semibold' className='my-2' > | ||||||||
{categoryName} | ||||||||
</Heading> | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment, explaining about this
useEffect
block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It scrolls the page to a specific category referenced in the URL hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akshatnema Done Sir