1
- import { MutableRefObject , useContext , useEffect , useState } from "react" ;
1
+ import {
2
+ MutableRefObject ,
3
+ SetStateAction ,
4
+ useContext ,
5
+ useEffect ,
6
+ useState ,
7
+ } from "react" ;
2
8
import { animated , useTransition } from "react-spring" ;
3
9
import "./styles/HVContent.css" ;
4
10
import Deerfall from "./projects/Deerfall" ;
@@ -22,6 +28,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
22
28
const navigate = useNavigate ( ) ;
23
29
// - - - - CONTEXT - - - -
24
30
const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
31
+ const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
25
32
const observerOptions : IntersectionObserverInit = {
26
33
threshold : 0.5 ,
27
34
root : null ,
@@ -107,26 +114,46 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
107
114
} , [ allParams ] ) ;
108
115
109
116
useEffect ( ( ) => {
110
- if ( mediaScrollObserver ?. isIntersecting ) {
117
+ if ( mediaScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
111
118
navigate ( `${ location . pathname } #media` ) ;
112
119
}
113
120
} , [ mediaScrollObserver ?. isIntersecting ] ) ;
114
121
115
122
useEffect ( ( ) => {
116
- if ( techScrollObserver ?. isIntersecting )
123
+ if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering )
117
124
navigate ( `${ location . pathname } #tech` ) ;
118
125
} , [ techScrollObserver ?. isIntersecting ] ) ;
119
126
120
127
useEffect ( ( ) => {
121
- if ( blogScrollObserver ?. isIntersecting )
128
+ if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering )
122
129
navigate ( `${ location . pathname } #blog` ) ;
123
130
} , [ blogScrollObserver ?. isIntersecting ] ) ;
124
131
125
132
useEffect ( ( ) => {
126
- if ( aboutScrollObserver ?. isIntersecting )
133
+ if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering )
127
134
navigate ( `${ location . pathname } #about` ) ;
128
135
} , [ aboutScrollObserver ?. isIntersecting ] ) ;
129
136
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
+
130
157
return (
131
158
< main className = 'HVContent' >
132
159
{ isIntro ? (
@@ -138,6 +165,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
138
165
scrollRefs = { scrollRefs }
139
166
hueRotation = { hueRotation }
140
167
scrollToElement = { scrollToElement }
168
+ setScrollIsBuffering = { setScrollIsBuffering }
141
169
/>
142
170
) }
143
171
0 commit comments