1+
2+ "use client" ;
3+
14import React , { useEffect , useRef , useState } from "react" ;
25import { About } from "@components/css/about" ;
36import { Skills as CV } from "@components/cv" ;
@@ -11,6 +14,7 @@ import { History } from "@components/history";
1114import { ContentExpander } from "@components/contentExpander" ;
1215import { AnimatedMe } from "@components/animated_me" ;
1316import { Expandable } from "@src/lib/expandable" ;
17+ import { usePathname } from 'next/navigation'
1418
1519interface PageInfo {
1620 page : JSX . Element ,
@@ -28,29 +32,34 @@ const pageOptions: PageInfo[] = [
2832 return { url : `/${ info . name } ` , ...info }
2933} )
3034
35+
3136export const Main : React . FC = ( ) => {
32- const [ selectedPage , selectPage ] = useState < PageInfo | null > ( null )
37+ const initial_page = pageOptions . find ( info => info . url == usePathname ( ) )
38+
39+ const [ selectedPage , selectPage ] = useState < PageInfo | null > ( initial_page || null )
3340 const [ showExtra , setShowExtra ] = useState ( false ) ;
3441
3542 const contentRef = useRef < HTMLDivElement > ( null )
43+ const [ initialRenderComplete , setInitialRenderComplete ] = React . useState ( false ) ;
3644
37- //load page from history on first load
45+ // load page from history on first load
3846 useEffect ( ( ) => {
39- if ( window . history . state != null ) {
40- const new_page = pageOptions . find ( info => info . url == window . history . state . as )
41- if ( new_page != null ) {
42- selectPage ( new_page )
43- }
47+ if ( initial_page != null ) {
48+ selectPage ( initial_page )
4449 }
50+ setInitialRenderComplete ( true ) ;
4551 } , [ ] ) ;
4652
4753 //copy state to history on page change
4854 useEffect ( ( ) => {
4955 window . history . pushState ( { } , "" , selectedPage ?. url ?? "/" ) ;
5056 } , [ selectedPage ] ) ;
5157
52- const showContent = selectedPage != null ;
58+ // if (!initialRenderComplete) {
59+ // return null;
60+ // }
5361
62+ const showContent = selectedPage != null ;
5463
5564 return (
5665 < div style = { { display : 'flex' , flexDirection : 'column' , minHeight : '100vh' , alignItems : 'stretch' } } >
@@ -71,17 +80,19 @@ export const Main: React.FC = () => {
7180 < img src = "images/profile.jpg" width = { 180 } height = { 180 } style = { { marginRight : 8 , marginTop : 16 } } />
7281 </ div >
7382
74- < div className = "nav" role = "navigation" > < PageSelector < PageInfo >
83+
84+ { ! initialRenderComplete ? null : < div className = "nav" role = "navigation" > < PageSelector < PageInfo >
7585 options = { pageOptions }
7686 selected = { selectedPage }
7787 onSelected = { ( el ) => {
7888 selectPage ( el == selectedPage ? null : el ) ;
7989 } }
8090 />
81- </ div >
91+ </ div > }
8292
8393 < div className = "expandingHome" style = { { margin : 'auto' } } >
84- < Expandable expanded = { ! showContent } >
94+
95+ { ! initialRenderComplete ? null : < Expandable expanded = { ! showContent } >
8596 < div style = { { display : 'flex' , flexDirection : 'row' , justifyContent : 'center' , alignItems : 'center' } } >
8697 < ContentExpander expanded = { showExtra } maxSize = { 64 } onClick = { ( ) => setShowExtra ( ! showExtra ) } />
8798 < Expandable expanded = { ! showExtra } horizontal >
@@ -99,15 +110,17 @@ export const Main: React.FC = () => {
99110 </ Expandable >
100111 </ Expandable >
101112 </ div >
102- </ Expandable >
113+ </ Expandable > }
103114 </ div >
104115
105- < Expandable expanded = { showContent } >
116+
117+
118+ { ! initialRenderComplete ? null : < Expandable expanded = { showContent } >
106119 < div ref = { contentRef } className = { styles . content } >
107120 < div className = "not-print" style = { { margin : '32px 24px' , padding : '32px 0' } } > { selectedPage ?. page } </ div >
108121 < div className = "print-only" style = { { margin : '32px 24px' , marginBottom : 0 } } > { selectedPage ?. page } </ div >
109122 </ div >
110- </ Expandable >
123+ </ Expandable > }
111124
112125
113126 < div className = "footer" style = { { display : 'flex' , flexDirection : 'row' , justifyContent : 'space-between' } } >
0 commit comments