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

fixes down arrow scroll behavior on homepage #2495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/User/components/DownArrow/downArrow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import "../../pages/Home/Home.css";
import Arrow from "../../../assets/arrow.png";
// Make sure to update the path to your actual image location

const DownArrow = () => {
const DownArrow = ({scrollToCategories}) => {
return (
<div className="down-arrow flex justify-center items-center">
<img
className="w-12 mt-32 hover:cursor-pointer"
src={Arrow}
alt="Down Arrow"
id="arrow"
onClick={scrollToCategories}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add fallback for scrollToCategories prop

The onClick handler will cause a runtime error if the scrollToCategories prop is not provided. Consider adding a default fallback.

import React from "react";
import "../../pages/Home/Home.css";
import Arrow from "../../../assets/arrow.png";
import PropTypes from "prop-types";
// Make sure to update the path to your actual image location

const DownArrow = ({scrollToCategories}) => {
  return (
    <div className="down-arrow flex justify-center items-center">
      <img
        className="w-12 mt-32 hover:cursor-pointer"
        src={Arrow}
        alt="Down Arrow"
        id="arrow"
-        onClick={scrollToCategories}
+        onClick={scrollToCategories || (() => {})}
      />
    </div>
  );
};

DownArrow.propTypes = {
  scrollToCategories: PropTypes.func.isRequired
};

export default DownArrow;
📝 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
onClick={scrollToCategories}
import React from "react";
import "../../pages/Home/Home.css";
import Arrow from "../../../assets/arrow.png";
import PropTypes from "prop-types";
// Make sure to update the path to your actual image location
const DownArrow = ({scrollToCategories}) => {
return (
<div className="down-arrow flex justify-center items-center">
<img
className="w-12 mt-32 hover:cursor-pointer"
src={Arrow}
alt="Down Arrow"
id="arrow"
onClick={scrollToCategories || (() => {})}
/>
</div>
);
};
DownArrow.propTypes = {
scrollToCategories: PropTypes.func.isRequired
};
export default DownArrow;

/>
</div>
);
Expand Down
9 changes: 7 additions & 2 deletions src/User/pages/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const latestProducts = [

const Home = () => {
const sectionRef = useRef(null);
const categoriesRef = useRef(null);
const [searchTerm, setSearchTerm] = useState("");
const [suggestions, setSuggestions] = useState([]);
const navigate = useNavigate();
Expand Down Expand Up @@ -163,6 +164,10 @@ const Home = () => {
sectionRef.current.scrollIntoView({ behavior: "smooth" });
};

const scrollToCategories=()=>{
categoriesRef.current.scrollIntoView({behavior:"smooth"});
}


const handleSubscribe = (e) => {
e.preventDefault();
Expand Down Expand Up @@ -220,12 +225,12 @@ const Home = () => {
className="bg-green-700 text-white px-6 sm:px-8 py-2 sm:py-3 rounded-full text-base sm:text-lg font-semibold hover:bg-green-800 transition duration-300">
Shop Now
</button>
<DownArrow />
<DownArrow scrollToCategories={scrollToCategories} />
</div>
</div>
</section>
{/* Popular Categories */}
<section className="py-8 sm:py-12 md:py-16 bg-[#fff0e3ff]">
<section className="py-8 sm:py-12 md:py-16 bg-[#fff0e3ff]" ref={categoriesRef} >
<div className="container mx-auto px-4">
<h2 className="text-xl sm:text-2xl md:text-3xl font-bold mb-6 md:mb-8 text-black">
Popular Categories
Expand Down