Skip to content

Commit 6e7302b

Browse files
committed
Refactor HackathonList component to simplify scrolling behavior and remove unnecessary container reference
1 parent f2386c7 commit 6e7302b

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

src/Page/OpportunitiesHub/HackathonList.jsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,6 @@ const HackathonListContainer = styled.div`
765765
justify-content: center;
766766
gap: 0.5rem; /* Decreased gap */
767767
padding: 1rem;
768-
max-height: 80vh;
769-
overflow-y: auto;
770768
771769
@media (min-width: 768px) {
772770
justify-content: space-around;
@@ -824,7 +822,6 @@ const HackathonList = () => {
824822
const [domainFilter, setDomainFilter] = useState('');
825823
const [highlightId, setHighlightId] = useState(null);
826824
const cardRefs = useRef({});
827-
const containerRef = useRef(null);
828825

829826
// Filter logic
830827
const filteredHackathons = hackathons.filter((hackathon) => {
@@ -859,21 +856,13 @@ const HackathonList = () => {
859856
}, [locationFilter, monthFilter, domainFilter]);
860857

861858
useEffect(() => {
862-
if (highlightId && cardRefs.current[highlightId] && containerRef.current) {
863-
const card = cardRefs.current[highlightId];
864-
const container = containerRef.current;
865-
// Scroll so the card is centered in the container
866-
const cardTop = card.offsetTop;
867-
const cardHeight = card.offsetHeight;
868-
const containerHeight = container.offsetHeight;
869-
container.scrollTo({
870-
top: cardTop - containerHeight / 2 + cardHeight / 2,
871-
behavior: 'smooth',
872-
});
873-
card.style.boxShadow = '0 0 0 4px #00a6fb, 0 0 20px #00a6fb';
874-
card.style.transition = 'box-shadow 0.5s';
859+
if (highlightId && cardRefs.current[highlightId]) {
860+
const el = cardRefs.current[highlightId];
861+
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
862+
el.style.boxShadow = '0 0 0 4px #00a6fb, 0 0 20px #00a6fb';
863+
el.style.transition = 'box-shadow 0.5s';
875864
setTimeout(() => {
876-
card.style.boxShadow = '';
865+
el.style.boxShadow = '';
877866
}, 2000);
878867
}
879868
}, [highlightId, displayHackathons.length]);
@@ -909,7 +898,7 @@ const HackathonList = () => {
909898
onChange={(e) => setDomainFilter(e.target.value)}
910899
/>
911900
</FilterContainer>
912-
<HackathonListContainer ref={containerRef}>
901+
<HackathonListContainer>
913902
{displayHackathons.map((hackathon) => (
914903
<HackathonCardComponent
915904
key={hackathon.shareLink}

0 commit comments

Comments
 (0)