Skip to content

Commit

Permalink
fix: fix toggle promobar state change to only happen when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyagabriel committed Oct 6, 2024
1 parent 50215ad commit 4e08b74
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/components/Header/Promobar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ export function Promobar() {
useEffect(() => {
const setPromobarVisibility = () => {
if (document.body.style.position === 'fixed') return;
togglePromobar(
const promobarShouldBeOpen =
window.scrollY <=
(typeof promobarHeight === 'string'
? parseInt(promobarHeight, 10)
: Number(promobarHeight)),
);
(typeof promobarHeight === 'string'
? parseInt(promobarHeight, 10)
: Number(promobarHeight));
if (promobarOpen && !promobarShouldBeOpen) togglePromobar(false);
else if (!promobarOpen && promobarShouldBeOpen) togglePromobar(true);
};

if (!autohide) {
Expand All @@ -72,7 +73,7 @@ export function Promobar() {
return () => {
window.removeEventListener('scroll', setPromobarVisibility);
};
}, [autohide, promobarHeight]);
}, [autohide, promobarHeight, promobarOpen]);

return (
<div
Expand Down

0 comments on commit 4e08b74

Please sign in to comment.