1- import {
2- MutableRefObject ,
3- SetStateAction ,
4- useContext ,
5- useEffect ,
6- useState ,
7- } from "react" ;
1+ import { SetStateAction , useContext , useEffect , useState } from "react" ;
82import { animated , useTransition } from "react-spring" ;
93import "./styles/HVContent.css" ;
104import Deerfall from "./projects/Deerfall" ;
@@ -22,13 +16,13 @@ interface Props {
2216}
2317
2418const HVContent = ( { project, isIntro, allParams } : Props ) => {
25- // - - - - STATES - - - -
19+ // = = = = = NAVIGATION = = = = =
2620 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 ) ;
2724 const location = useLocation ( ) ;
2825 const navigate = useNavigate ( ) ;
29- // - - - - CONTEXT - - - -
30- const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
31- const [ scrollIsBuffering , setScrollIsBuffering ] = useState ( false ) ;
3226 const observerOptions : IntersectionObserverInit = {
3327 threshold : 0.5 ,
3428 root : null ,
@@ -55,7 +49,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
5549 false
5650 ) ;
5751
58- // - - - - PROJECTS - - - -
52+ // = = = = = PROJECTS = = = = =
5953 const allProjList = {
6054 intro : < Introduction /> ,
6155 deerfall : < Deerfall isPortfolio = { isPortfolio } /> ,
@@ -69,7 +63,7 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
6963 } ;
7064 const [ localProject , setLocalProject ] = useState < string > ( "" ) ;
7165 const [ show , setShow ] = useState < boolean > ( true ) ;
72- // - - - - TRANSITIONS - - - -
66+ // = = = = = TRANSITIONS = = = = =
7367 const transitionFade = useTransition ( show , {
7468 from : { opacity : 0 } ,
7569 enter : { opacity : 1 } ,
@@ -89,7 +83,10 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
8983 } ;
9084
9185 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" ) ;
9390 } ;
9491
9592 // = = = = = USE EFFECTS = = = = =
@@ -116,42 +113,41 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
116113 useEffect ( ( ) => {
117114 if ( mediaScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
118115 navigate ( `${ location . pathname } #media` ) ;
119- }
120- } , [ mediaScrollObserver ?. isIntersecting ] ) ;
121-
122- useEffect ( ( ) => {
123- if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering )
116+ } else if ( techScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
124117 navigate ( `${ location . pathname } #tech` ) ;
125- } , [ techScrollObserver ?. isIntersecting ] ) ;
126-
127- useEffect ( ( ) => {
128- if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering )
118+ } else if ( blogScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
129119 navigate ( `${ location . pathname } #blog` ) ;
130- } , [ blogScrollObserver ?. isIntersecting ] ) ;
131-
132- useEffect ( ( ) => {
133- if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering )
120+ } else if ( aboutScrollObserver ?. isIntersecting && ! scrollIsBuffering ) {
134121 navigate ( `${ location . pathname } #about` ) ;
135- } , [ aboutScrollObserver ?. isIntersecting ] ) ;
122+ }
123+ } , [
124+ mediaScrollObserver ?. isIntersecting ,
125+ techScrollObserver ?. isIntersecting ,
126+ blogScrollObserver ?. isIntersecting ,
127+ aboutScrollObserver ?. isIntersecting ,
128+ ] ) ;
136129
137130 useEffect ( ( ) => {
131+ setScrollIsBuffering ( true ) ;
138132 if ( location . hash === "#media" ) {
139133 scrollToElement ( scrollRefs . media ) ;
134+ setCurrentNav ( "media" ) ;
140135 } else if ( location . hash === "#tech" ) {
141136 scrollToElement ( scrollRefs . tech ) ;
137+ setCurrentNav ( "tech" ) ;
142138 } else if ( location . hash === "#about" ) {
143139 scrollToElement ( scrollRefs . about ) ;
140+ setCurrentNav ( "about" ) ;
144141 } else if ( location . hash === "#blog" ) {
145142 scrollToElement ( scrollRefs . blog ) ;
143+ setCurrentNav ( "blog" ) ;
146144 }
147- console . log ( location . hash ) ;
148145 } , [ location . hash ] ) ;
149146
150147 useEffect ( ( ) => {
151148 if ( scrollIsBuffering ) {
152- setTimeout ( ( ) => setScrollIsBuffering ( false ) , 800 ) ;
149+ setTimeout ( ( ) => setScrollIsBuffering ( false ) , 500 ) ;
153150 }
154- console . log ( scrollIsBuffering ) ;
155151 } , [ scrollIsBuffering ] ) ;
156152
157153 return (
@@ -162,9 +158,9 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
162158 < HVSideNav
163159 isPortfolio = { isPortfolio }
164160 allParams = { allParams }
165- scrollRefs = { scrollRefs }
166161 hueRotation = { hueRotation }
167- scrollToElement = { scrollToElement }
162+ currentNav = { currentNav }
163+ setCurrentNav = { setCurrentNav }
168164 setScrollIsBuffering = { setScrollIsBuffering }
169165 />
170166 ) }
0 commit comments