1- import { MutableRefObject , useContext , useEffect , useState } from "react" ;
1+ import {
2+ MutableRefObject ,
3+ SetStateAction ,
4+ useContext ,
5+ useEffect ,
6+ useState ,
7+ } from "react" ;
28import { animated , useTransition } from "react-spring" ;
39import "./styles/HVContent.css" ;
410import Deerfall from "./projects/Deerfall" ;
@@ -22,6 +28,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
2228 const navigate = useNavigate ( ) ;
2329 // - - - - CONTEXT - - - -
2430 const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
31+ const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
2532 const observerOptions : IntersectionObserverInit = {
2633 threshold : 0.5 ,
2734 root : null ,
@@ -107,26 +114,46 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
107114 } , [ allParams ] ) ;
108115
109116 useEffect ( ( ) => {
110- if ( mediaScrollObserver ?. isIntersecting ) {
117+ if ( mediaScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
111118 navigate ( `${ location . pathname } #media` ) ;
112119 }
113120 } , [ mediaScrollObserver ?. isIntersecting ] ) ;
114121
115122 useEffect ( ( ) => {
116- if ( techScrollObserver ?. isIntersecting )
123+ if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering )
117124 navigate ( `${ location . pathname } #tech` ) ;
118125 } , [ techScrollObserver ?. isIntersecting ] ) ;
119126
120127 useEffect ( ( ) => {
121- if ( blogScrollObserver ?. isIntersecting )
128+ if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering )
122129 navigate ( `${ location . pathname } #blog` ) ;
123130 } , [ blogScrollObserver ?. isIntersecting ] ) ;
124131
125132 useEffect ( ( ) => {
126- if ( aboutScrollObserver ?. isIntersecting )
133+ if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering )
127134 navigate ( `${ location . pathname } #about` ) ;
128135 } , [ aboutScrollObserver ?. isIntersecting ] ) ;
129136
137+ useEffect ( ( ) => {
138+ if ( location . hash === "#media" ) {
139+ scrollToElement ( scrollRefs . media ) ;
140+ } else if ( location . hash === "#tech" ) {
141+ scrollToElement ( scrollRefs . tech ) ;
142+ } else if ( location . hash === "#about" ) {
143+ scrollToElement ( scrollRefs . about ) ;
144+ } else if ( location . hash === "#blog" ) {
145+ scrollToElement ( scrollRefs . blog ) ;
146+ }
147+ console . log ( location . hash ) ;
148+ } , [ location . hash ] ) ;
149+
150+ useEffect ( ( ) => {
151+ if ( scrollIsBuffering ) {
152+ setTimeout ( ( ) => setScrollIsBuffering ( false ) , 800 ) ;
153+ }
154+ console . log ( scrollIsBuffering ) ;
155+ } , [ scrollIsBuffering ] ) ;
156+
130157 return (
131158 < main className = 'HVContent' >
132159 { isIntro ? (
@@ -138,6 +165,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
138165 scrollRefs = { scrollRefs }
139166 hueRotation = { hueRotation }
140167 scrollToElement = { scrollToElement }
168+ setScrollIsBuffering = { setScrollIsBuffering }
141169 />
142170 ) }
143171
0 commit comments