1
- import { useEffect , useState } from "react" ;
1
+ import { SetStateAction , useContext , useEffect , useState } from "react" ;
2
2
import { animated , useTransition } from "react-spring" ;
3
3
import "./styles/HVContent.css" ;
4
4
import Deerfall from "./projects/Deerfall" ;
5
5
import MediaMatchup from "./projects/MediaMatchup" ;
6
6
import Introduction from "./Introduction" ;
7
+ import HVSideNav from "./HVSideNav" ;
8
+ import AppContext from "../contexts/AppContext" ;
9
+ import { useIntersectionObserver } from "../hooks/useIntersectionObserver" ;
10
+ import { useLocation , useNavigate } from "react-router-dom" ;
7
11
8
12
interface Props {
9
13
project : string ;
@@ -12,9 +16,40 @@ interface Props {
12
16
}
13
17
14
18
const HVContent = ( { project, isIntro, allParams } : Props ) => {
15
- // - - - - STATES - - - -
19
+ // = = = = = NAVIGATION = = = = =
16
20
const [ isPortfolio , setIsPortfolio ] = useState < boolean > ( true ) ;
17
- // - - - - PROJECTS - - - -
21
+ const [ currentNav , setCurrentNav ] = useState < string > ( "media" ) ;
22
+ const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
23
+ const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
24
+ const location = useLocation ( ) ;
25
+ const navigate = useNavigate ( ) ;
26
+ const observerOptions : IntersectionObserverInit = {
27
+ threshold : 0.5 ,
28
+ root : null ,
29
+ rootMargin : "0px" ,
30
+ } ;
31
+ const mediaScrollObserver = useIntersectionObserver (
32
+ scrollRefs . media ,
33
+ observerOptions ,
34
+ false
35
+ ) ;
36
+ const techScrollObserver = useIntersectionObserver (
37
+ scrollRefs . tech ,
38
+ observerOptions ,
39
+ false
40
+ ) ;
41
+ const blogScrollObserver = useIntersectionObserver (
42
+ scrollRefs . blog ,
43
+ observerOptions ,
44
+ false
45
+ ) ;
46
+ const aboutScrollObserver = useIntersectionObserver (
47
+ scrollRefs . about ,
48
+ observerOptions ,
49
+ false
50
+ ) ;
51
+
52
+ // = = = = = PROJECTS = = = = =
18
53
const allProjList = {
19
54
intro : < Introduction /> ,
20
55
deerfall : < Deerfall isPortfolio = { isPortfolio } /> ,
@@ -28,7 +63,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
28
63
} ;
29
64
const [ localProject , setLocalProject ] = useState < string > ( "" ) ;
30
65
const [ show , setShow ] = useState < boolean > ( true ) ;
31
- // - - - - TRANSITIONS - - - -
66
+ // = = = = = TRANSITIONS = = = = =
32
67
const transitionFade = useTransition ( show , {
33
68
from : { opacity : 0 } ,
34
69
enter : { opacity : 1 } ,
@@ -37,6 +72,8 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
37
72
// exitBeforeEnter: true,
38
73
} ) ;
39
74
75
+ // = = = = = FUNCTIONS = = = = =
76
+
40
77
const checkAndSetProjComp = ( ) => {
41
78
if ( isIntro ) {
42
79
setLocalProject ( "intro" ) ;
@@ -45,7 +82,14 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
45
82
}
46
83
} ;
47
84
48
- // - - - - - USE EFFECTS - - - - -
85
+ const scrollToElement = ( ref : React . MutableRefObject < any > ) => {
86
+ ref . current ?. scrollIntoView ( {
87
+ behavior : "smooth" ,
88
+ } ) ;
89
+ console . log ( "scrollToElement Triggered" ) ;
90
+ } ;
91
+
92
+ // = = = = = USE EFFECTS = = = = =
49
93
// Hide Project when it is Changed, then set the new project once hidden
50
94
useEffect ( ( ) => {
51
95
setShow ( false ) ;
@@ -66,8 +110,61 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
66
110
}
67
111
} , [ allParams ] ) ;
68
112
113
+ useEffect ( ( ) => {
114
+ if ( mediaScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
115
+ navigate ( `${ location . pathname } #media` ) ;
116
+ } else if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
117
+ navigate ( `${ location . pathname } #tech` ) ;
118
+ } else if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
119
+ navigate ( `${ location . pathname } #blog` ) ;
120
+ } else if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
121
+ navigate ( `${ location . pathname } #about` ) ;
122
+ }
123
+ } , [
124
+ mediaScrollObserver ?. isIntersecting ,
125
+ techScrollObserver ?. isIntersecting ,
126
+ blogScrollObserver ?. isIntersecting ,
127
+ aboutScrollObserver ?. isIntersecting ,
128
+ ] ) ;
129
+
130
+ useEffect ( ( ) => {
131
+ setScrollIsBuffering ( true ) ;
132
+ if ( location . hash === "#media" ) {
133
+ scrollToElement ( scrollRefs . media ) ;
134
+ setCurrentNav ( "media" ) ;
135
+ } else if ( location . hash === "#tech" ) {
136
+ scrollToElement ( scrollRefs . tech ) ;
137
+ setCurrentNav ( "tech" ) ;
138
+ } else if ( location . hash === "#about" ) {
139
+ scrollToElement ( scrollRefs . about ) ;
140
+ setCurrentNav ( "about" ) ;
141
+ } else if ( location . hash === "#blog" ) {
142
+ scrollToElement ( scrollRefs . blog ) ;
143
+ setCurrentNav ( "blog" ) ;
144
+ }
145
+ } , [ location . hash ] ) ;
146
+
147
+ useEffect ( ( ) => {
148
+ if ( scrollIsBuffering ) {
149
+ setTimeout ( ( ) => setScrollIsBuffering ( false ) , 500 ) ;
150
+ }
151
+ } , [ scrollIsBuffering ] ) ;
152
+
69
153
return (
70
- < div className = 'HVContent' >
154
+ < main className = 'HVContent' >
155
+ { isIntro ? (
156
+ ""
157
+ ) : (
158
+ < HVSideNav
159
+ isPortfolio = { isPortfolio }
160
+ allParams = { allParams }
161
+ hueRotation = { hueRotation }
162
+ currentNav = { currentNav }
163
+ setCurrentNav = { setCurrentNav }
164
+ setScrollIsBuffering = { setScrollIsBuffering }
165
+ />
166
+ ) }
167
+
71
168
{ transitionFade (
72
169
( styles , item ) =>
73
170
item && (
@@ -76,7 +173,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
76
173
</ animated . div >
77
174
)
78
175
) }
79
- </ div >
176
+ </ main >
80
177
) ;
81
178
} ;
82
179
0 commit comments