Skip to content

Commit

Permalink
refactor: describe SIGNIFICANT_SCROLL_OFFSET variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Bagautdinov committed Sep 12, 2024
1 parent 55a48a7 commit a1be93e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/SubNavigation/hooks/useVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {useCallback, useEffect, useState} from 'react';

// value in px equal to the distance after which the scroll will update the states
const SIGNIFICANT_SCROLL_OFFSET = 55;

const useVisibility = (
menuOpened: boolean,
miniTocOpen: boolean,
Expand All @@ -17,7 +20,7 @@ const useVisibility = (
return setLastScrollY(scrollY);
}

if (miniTocOpen || menuOpened || scrollY < 55) {
if (miniTocOpen || menuOpened || scrollY < SIGNIFICANT_SCROLL_OFFSET) {
if (visible) {
return;
}
Expand All @@ -33,7 +36,7 @@ const useVisibility = (

const scrollDiff = Math.abs(scrollY - lastScrollY);

if (hiddingTimeout || scrollDiff < 55) {
if (hiddingTimeout || scrollDiff < SIGNIFICANT_SCROLL_OFFSET) {
return;
}

Expand All @@ -50,7 +53,7 @@ const useVisibility = (
const setVisibility = useCallback((value: boolean) => setVisibilityLocal(value), []);

useEffect(() => {
if (window.scrollY < 50) {
if (window.scrollY < SIGNIFICANT_SCROLL_OFFSET) {
return;
}

Expand Down

0 comments on commit a1be93e

Please sign in to comment.