Skip to content

Commit 0dd66f7

Browse files
authored
Merge branch 'main' into fix/testimonials-carousel-swipe-navigation
2 parents 56ed53b + d3c9109 commit 0dd66f7

5 files changed

Lines changed: 73 additions & 9 deletions

File tree

src/common/header/Header.jsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import HeaderNav from './HeaderNav';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
33
import { Link, useLocation } from 'react-router-dom';
44
import Countdown from 'react-countdown';
55
import './header.css';
@@ -10,6 +10,50 @@ const Header = () => {
1010
const pathName = location.pathname;
1111

1212
const [reset, setReset] = useState({ search: false, filter: false });
13+
const [showNav, setShowNav] = useState(true);
14+
const lastScrollY = useRef(0);
15+
16+
useEffect(() => {
17+
const handleScroll = () => {
18+
const current = window.scrollY;
19+
20+
const hero = document.getElementById('hero');
21+
22+
if (hero) {
23+
const heroBottom = hero.getBoundingClientRect().bottom;
24+
const headerHeight = 64; // your navbar height
25+
26+
const banner = document.querySelector('.activity-timer-banner');
27+
const bannerHeight = banner?.offsetHeight || 0;
28+
29+
if (heroBottom > headerHeight + bannerHeight) {
30+
setShowNav(true);
31+
lastScrollY.current = current;
32+
33+
return;
34+
}
35+
}
36+
37+
// after hero → direction based (with threshold)
38+
const SCROLL_THRESHOLD = 20;
39+
const diff = Math.abs(current - lastScrollY.current);
40+
41+
// ignore tiny scrolls
42+
if (diff < SCROLL_THRESHOLD) return;
43+
44+
if (current > lastScrollY.current) {
45+
setShowNav(false); // down
46+
} else {
47+
setShowNav(true); // up
48+
}
49+
50+
lastScrollY.current = current;
51+
};
52+
53+
window.addEventListener('scroll', handleScroll);
54+
55+
return () => window.removeEventListener('scroll', handleScroll);
56+
}, []);
1357

1458
useEffect(() => {
1559
if (location.state) {
@@ -95,7 +139,7 @@ const Header = () => {
95139
};
96140

97141
return (
98-
<>
142+
<div className={`nav-wrapper ${showNav ? 'nav--visible' : 'nav--hidden'}`}>
99143
{process.env.REACT_APP_ACTIVITIES_ON === 'true' && showHideBits.showActivityTimer && (
100144
<Countdown date={new Date(1675209600000)} renderer={activityTimerRenderer} />
101145
)}
@@ -122,7 +166,7 @@ const Header = () => {
122166

123167
<HeaderNav showBrowse={showHideBits.showBrowse} />
124168
</header>
125-
</>
169+
</div>
126170
);
127171
};
128172

src/common/header/header.css

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
.app-header {
2-
position: relative;
2+
/* position: fixed;
33
top: 0;
44
right: 0;
5-
left: 0;
5+
left: 0; */
6+
transition: transform 0.3s ease;
67
z-index: 10;
78
display: flex;
89
justify-content: space-between;
@@ -14,14 +15,33 @@
1415
padding: 0 1rem 0 0.6rem;
1516
}
1617

18+
.nav-wrapper {
19+
position: fixed;
20+
top: 0;
21+
left: 0;
22+
right: 0;
23+
z-index: 10;
24+
transition: transform 0.3s ease;
25+
}
26+
27+
.nav--hidden {
28+
transform: translateY(-100%);
29+
}
30+
31+
.nav--visible {
32+
transform: translateY(0);
33+
}
34+
35+
36+
1737
@media screen and (max-width: 768px) {
1838
.app-header {
1939
padding: 0 1rem 0 0.2rem;
2040
}
2141
}
2242

2343
.app-header-home {
24-
position: sticky;
44+
/* position: sticky; */
2545
}
2646

2747
.app-header-home.app-header-home--promo {

src/common/home/Home.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import DefaultBanner from 'common/defaultBanner/DefaultBanner';
1212
const Home = () => {
1313
return (
1414
<main>
15-
<section className="app-home-body">
15+
<section className="app-home-body" id="hero">
1616
<DefaultBanner />
1717
</section>
1818
<section className="home-features">

src/common/playleaderboard/TopPlayCreators.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const TopPlayCreators = ({ topPlayCreators }) => {
1414
const secondPlace = topPlayCreators.length > 1 ? topPlayCreators[1] : null;
1515
const thirdPlace = topPlayCreators.length > 2 ? topPlayCreators[2] : null;
1616

17-
const renderRankIcon = (rank) => {
17+
const renderRankIcon = () => {
1818
return <TagRoundedIcon className="rank-icon rank-same" />;
1919
};
2020

src/common/playlists/PlayCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import userImage from 'images/user.png';
99
const formatDate = (dateString) => dateString || '';
1010

1111
function PlayCard({ play, cover, likeObject }) {
12-
const [isExpanded, setIsExpanded] = useState(false);
12+
const [isExpanded] = useState(false);
1313
if (!play || !play.github || !play.slug) return null;
1414

1515
const avatarSrc =

0 commit comments

Comments
 (0)