1- import { useEffect , useState } from "react" ;
1+ import { MutableRefObject , useContext , useEffect , useState } from "react" ;
22import { animated , useTransition } from "react-spring" ;
33import "./styles/HVContent.css" ;
44import Deerfall from "./projects/Deerfall" ;
55import MediaMatchup from "./projects/MediaMatchup" ;
66import Introduction from "./Introduction" ;
7- import mediaIcon from "../img/navIcons/media.png" ;
8- import techIcon from "../img/navIcons/tech.png" ;
9- import aboutIcon from "../img/navIcons/about.png" ;
10- import blogIcon from "../img/navIcons/blog.png" ;
117import HVSideNav from "./HVSideNav" ;
8+ import AppContext from "../contexts/AppContext" ;
9+ import { useIntersectionObserver } from "../hooks/useIntersectionObserver" ;
10+ import { useLocation , useNavigate } from "react-router-dom" ;
1211
1312interface Props {
1413 project : string ;
@@ -19,6 +18,36 @@ interface Props {
1918const HVContent = ( { project, isIntro, allParams } : Props ) => {
2019 // - - - - STATES - - - -
2120 const [ isPortfolio , setIsPortfolio ] = useState < boolean > ( true ) ;
21+ const location = useLocation ( ) ;
22+ const navigate = useNavigate ( ) ;
23+ // - - - - CONTEXT - - - -
24+ const { scrollRefs, hueRotation } = useContext ( AppContext ) ;
25+ const observerOptions : IntersectionObserverInit = {
26+ threshold : 0.5 ,
27+ root : null ,
28+ rootMargin : "0px" ,
29+ } ;
30+ const mediaScrollObserver = useIntersectionObserver (
31+ scrollRefs . media ,
32+ observerOptions ,
33+ false
34+ ) ;
35+ const techScrollObserver = useIntersectionObserver (
36+ scrollRefs . tech ,
37+ observerOptions ,
38+ false
39+ ) ;
40+ const blogScrollObserver = useIntersectionObserver (
41+ scrollRefs . blog ,
42+ observerOptions ,
43+ false
44+ ) ;
45+ const aboutScrollObserver = useIntersectionObserver (
46+ scrollRefs . about ,
47+ observerOptions ,
48+ false
49+ ) ;
50+
2251 // - - - - PROJECTS - - - -
2352 const allProjList = {
2453 intro : < Introduction /> ,
@@ -42,6 +71,8 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
4271 // exitBeforeEnter: true,
4372 } ) ;
4473
74+ // = = = = = FUNCTIONS = = = = =
75+
4576 const checkAndSetProjComp = ( ) => {
4677 if ( isIntro ) {
4778 setLocalProject ( "intro" ) ;
@@ -50,7 +81,11 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
5081 }
5182 } ;
5283
53- // - - - - - USE EFFECTS - - - - -
84+ const scrollToElement = ( ref : React . MutableRefObject < any > ) => {
85+ ref . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
86+ } ;
87+
88+ // = = = = = USE EFFECTS = = = = =
5489 // Hide Project when it is Changed, then set the new project once hidden
5590 useEffect ( ( ) => {
5691 setShow ( false ) ;
@@ -71,9 +106,40 @@ const HVContent = ({ project, isIntro, allParams }: Props) => {
71106 }
72107 } , [ allParams ] ) ;
73108
109+ useEffect ( ( ) => {
110+ if ( mediaScrollObserver ?. isIntersecting ) {
111+ navigate ( `${ location . pathname } #media` ) ;
112+ }
113+ } , [ mediaScrollObserver ?. isIntersecting ] ) ;
114+
115+ useEffect ( ( ) => {
116+ if ( techScrollObserver ?. isIntersecting )
117+ navigate ( `${ location . pathname } #tech` ) ;
118+ } , [ techScrollObserver ?. isIntersecting ] ) ;
119+
120+ useEffect ( ( ) => {
121+ if ( blogScrollObserver ?. isIntersecting )
122+ navigate ( `${ location . pathname } #blog` ) ;
123+ } , [ blogScrollObserver ?. isIntersecting ] ) ;
124+
125+ useEffect ( ( ) => {
126+ if ( aboutScrollObserver ?. isIntersecting )
127+ navigate ( `${ location . pathname } #about` ) ;
128+ } , [ aboutScrollObserver ?. isIntersecting ] ) ;
129+
74130 return (
75131 < main className = 'HVContent' >
76- { isIntro ? "" : < HVSideNav isPortfolio = { isPortfolio } /> }
132+ { isIntro ? (
133+ ""
134+ ) : (
135+ < HVSideNav
136+ isPortfolio = { isPortfolio }
137+ allParams = { allParams }
138+ scrollRefs = { scrollRefs }
139+ hueRotation = { hueRotation }
140+ scrollToElement = { scrollToElement }
141+ />
142+ ) }
77143
78144 { transitionFade (
79145 ( styles , item ) =>
0 commit comments