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

added scroll feature in top contributor #435

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 28 additions & 1 deletion src/Components/MainContainer.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@
padding: 10px 20px;
}



.maincontainer .right .bottom_card {
height: 375px; /* Set a fixed height */
overflow-y: auto; /* Enable vertical scrolling */
scrollbar-width: none; /* Firefox */
}
.maincontainer .right .bottom_card::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}



.maincontainer .right .topCard .topCard_name,
.maincontainer .right .bottom_card .bottomCard_name {
display: flex;
Expand Down Expand Up @@ -391,7 +404,21 @@
width: 30px;
height: 30px;
}

.bottom_card {
height: 500px;
overflow-y: scroll;
}

.bottom_card::-webkit-scrollbar {
width: 0;
height: 0;
}

.bottom_card {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}

.maincontainer .right .bottom_card .topSeller {
margin: 20px 0;
}
Expand Down
54 changes: 41 additions & 13 deletions src/Components/MainRightBottomCard.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
import React, { useState } from "react";
import TopSeller from "./TopSeller";
import React, { useState, useEffect, useRef } from 'react';
import TopSeller from './TopSeller';

function MainRightBottomCard() {
const [visibleSellers, setVisibleSellers] = useState(3);
const [allSellersLoaded, setAllSellersLoaded] = useState(false);
const [showMore, setShowMore] = useState(false);
const profileListRef = useRef(null);

const loadMoreSellers = () => {
setVisibleSellers((prevVisibleSellers) => {
const newVisibleSellers = prevVisibleSellers + 3;
if (newVisibleSellers >= TopSeller.length) {
setAllSellersLoaded(true);
}
return newVisibleSellers;
});
};

useEffect(() => {
const handleScroll = () => {
if (profileListRef.current) {
const { scrollTop, clientHeight, scrollHeight } = profileListRef.current;
if (scrollTop + clientHeight >= scrollHeight - 10 && !allSellersLoaded) {
loadMoreSellers();
}
}
};

const profileListElem = profileListRef.current;
profileListElem.addEventListener('scroll', handleScroll);

return () => {
if (profileListElem) {
profileListElem.removeEventListener('scroll', handleScroll);
}
};
}, [allSellersLoaded]);

const handleViewMore = () => {
if (showMore) {
setVisibleSellers(3);
} else {
setVisibleSellers(TopSeller.length);
}
setShowMore(!showMore);
setShowMore((prevShowMore) => !prevShowMore);
setVisibleSellers((prevVisibleSellers) =>
showMore ? 3 : TopSeller.length
);
setAllSellersLoaded(!showMore); // Reset scroll loading state when toggling
};

return (
<div className="bottom_card">
<div className="bottom_card" ref={profileListRef}>
<div className="bottomCard_name">
<h2>Top Contributor</h2>
<a href="#" onClick={handleViewMore}>
Expand All @@ -33,14 +64,11 @@ function MainRightBottomCard() {
{seller?.seller_name} <span>{seller?.username}</span>
</p>
</div>
<a href="#" className="button">
Follow
</a>
<a href="#" className="button">Follow</a>
</div>
))}
</div>
);
}

export default MainRightBottomCard;

9 changes: 9 additions & 0 deletions src/Components/TopSeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import seller4 from "../img/seller4.jpg";
import seller5 from "../img/seller5.jpg";

const TopSeller = [
{ id: 4, seller_name: "Ralph Edwards", username: "@ralph", imgSrc: seller4 },

{ id: 1, seller_name: "Jane Cooper", username: "@jane", imgSrc: seller1 },
{ id: 2, seller_name: "Ariene McCoy", username: "@ariene", imgSrc: seller2 },
{ id: 3, seller_name: "Theresa Webb", username: "@theresa", imgSrc: seller3 },
{ id: 4, seller_name: "Ralph Edwards", username: "@ralph", imgSrc: seller4 },
{ id: 2, seller_name: "Ariene McCoy", username: "@ariene", imgSrc: seller2 },
{ id: 2, seller_name: "Ariene McCoy", username: "@ariene", imgSrc: seller2 },
{ id: 4, seller_name: "Ralph Edwards", username: "@ralph", imgSrc: seller4 },
{ id: 2, seller_name: "Ariene McCoy", username: "@ariene", imgSrc: seller2 },
{ id: 2, seller_name: "Ariene McCoy", username: "@ariene", imgSrc: seller2 },
{ id: 5, seller_name: "Raplhie", username: "@raplhie", imgSrc: seller5 },
{ id: 4, seller_name: "Ralph Edwards", username: "@ralph", imgSrc: seller4 },

];

export default TopSeller;
Loading
Loading