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

fix: navigation to correct heading in tools section #2790

Closed
wants to merge 14 commits into from
Closed
Changes from 2 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
15 changes: 14 additions & 1 deletion components/tools/ToolsList.js
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(() => {
Copy link
Member

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

@akshatnema Done Sir

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' });
}
}
}, []);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}, []);
}, []);

Copy link
Author

Choose a reason for hiding this comment

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

What changes to add here ?

Copy link
Member

Choose a reason for hiding this comment

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

just add a newline at the end of the file

Copy link
Member

Choose a reason for hiding this comment

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

clean code rules

Copy link
Author

Choose a reason for hiding this comment

The 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>
Expand Down
Loading