1
- import {
2
- MutableRefObject ,
3
- SetStateAction ,
4
- useContext ,
5
- useEffect ,
6
- useState ,
7
- } from "react" ;
1
+ import { SetStateAction , useContext , useEffect , useState } from "react" ;
8
2
import { animated , useTransition } from "react-spring" ;
9
3
import "./styles/HVContent.css" ;
10
4
import Deerfall from "./projects/Deerfall" ;
@@ -22,13 +16,13 @@ interface Props {
22
16
}
23
17
24
18
const HVContent = ( { project, isIntro, allParams } : Props ) => {
25
- // - - - - STATES - - - -
19
+ // = = = = = NAVIGATION = = = = =
26
20
const [ isPortfolio , setIsPortfolio ] = useState < boolean > ( true ) ;
21
+ const [ currentNav , setCurrentNav ] = useState < string > ( "media" ) ;
22
+ const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
23
+ const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
27
24
const location = useLocation ( ) ;
28
25
const navigate = useNavigate ( ) ;
29
- // - - - - CONTEXT - - - -
30
- const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
31
- const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
32
26
const observerOptions : IntersectionObserverInit = {
33
27
threshold : 0.5 ,
34
28
root : null ,
@@ -55,7 +49,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
55
49
false
56
50
) ;
57
51
58
- // - - - - PROJECTS - - - -
52
+ // = = = = = PROJECTS = = = = =
59
53
const allProjList = {
60
54
intro : < Introduction /> ,
61
55
deerfall : < Deerfall isPortfolio = { isPortfolio } /> ,
@@ -69,7 +63,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
69
63
} ;
70
64
const [ localProject , setLocalProject ] = useState < string > ( "" ) ;
71
65
const [ show , setShow ] = useState < boolean > ( true ) ;
72
- // - - - - TRANSITIONS - - - -
66
+ // = = = = = TRANSITIONS = = = = =
73
67
const transitionFade = useTransition ( show , {
74
68
from : { opacity : 0 } ,
75
69
enter : { opacity : 1 } ,
@@ -89,7 +83,10 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
89
83
} ;
90
84
91
85
const scrollToElement = ( ref : React . MutableRefObject < any > ) => {
92
- ref . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
86
+ ref . current ?. scrollIntoView ( {
87
+ behavior : "smooth" ,
88
+ } ) ;
89
+ console . log ( "scrollToElement Triggered" ) ;
93
90
} ;
94
91
95
92
// = = = = = USE EFFECTS = = = = =
@@ -116,42 +113,41 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
116
113
useEffect ( ( ) => {
117
114
if ( mediaScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
118
115
navigate ( `${ location . pathname } #media` ) ;
119
- }
120
- } , [ mediaScrollObserver ?. isIntersecting ] ) ;
121
-
122
- useEffect ( ( ) => {
123
- if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering )
116
+ } else if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
124
117
navigate ( `${ location . pathname } #tech` ) ;
125
- } , [ techScrollObserver ?. isIntersecting ] ) ;
126
-
127
- useEffect ( ( ) => {
128
- if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering )
118
+ } else if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
129
119
navigate ( `${ location . pathname } #blog` ) ;
130
- } , [ blogScrollObserver ?. isIntersecting ] ) ;
131
-
132
- useEffect ( ( ) => {
133
- if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering )
120
+ } else if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
134
121
navigate ( `${ location . pathname } #about` ) ;
135
- } , [ aboutScrollObserver ?. isIntersecting ] ) ;
122
+ }
123
+ } , [
124
+ mediaScrollObserver ?. isIntersecting ,
125
+ techScrollObserver ?. isIntersecting ,
126
+ blogScrollObserver ?. isIntersecting ,
127
+ aboutScrollObserver ?. isIntersecting ,
128
+ ] ) ;
136
129
137
130
useEffect ( ( ) => {
131
+ setScrollIsBuffering ( true ) ;
138
132
if ( location . hash === "#media" ) {
139
133
scrollToElement ( scrollRefs . media ) ;
134
+ setCurrentNav ( "media" ) ;
140
135
} else if ( location . hash === "#tech" ) {
141
136
scrollToElement ( scrollRefs . tech ) ;
137
+ setCurrentNav ( "tech" ) ;
142
138
} else if ( location . hash === "#about" ) {
143
139
scrollToElement ( scrollRefs . about ) ;
140
+ setCurrentNav ( "about" ) ;
144
141
} else if ( location . hash === "#blog" ) {
145
142
scrollToElement ( scrollRefs . blog ) ;
143
+ setCurrentNav ( "blog" ) ;
146
144
}
147
- console . log ( location . hash ) ;
148
145
} , [ location . hash ] ) ;
149
146
150
147
useEffect ( ( ) => {
151
148
if ( scrollIsBuffering ) {
152
- setTimeout ( ( ) => setScrollIsBuffering ( false ) , 800 ) ;
149
+ setTimeout ( ( ) => setScrollIsBuffering ( false ) , 500 ) ;
153
150
}
154
- console . log ( scrollIsBuffering ) ;
155
151
} , [ scrollIsBuffering ] ) ;
156
152
157
153
return (
@@ -162,9 +158,9 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
162
158
< HVSideNav
163
159
isPortfolio = { isPortfolio }
164
160
allParams = { allParams }
165
- scrollRefs = { scrollRefs }
166
161
hueRotation = { hueRotation }
167
- scrollToElement = { scrollToElement }
162
+ currentNav = { currentNav }
163
+ setCurrentNav = { setCurrentNav }
168
164
setScrollIsBuffering = { setScrollIsBuffering }
169
165
/>
170
166
) }
0 commit comments