@@ -4,9 +4,9 @@ import '@mdxeditor/editor/style.css';
4
4
import './styles/usdswebsite.override.css' ;
5
5
import "react-toastify/dist/ReactToastify.css" ;
6
6
import "./App.css" ;
7
- import { Fragment , useState } from "react" ;
7
+ import { Fragment , useReducer } from "react" ;
8
8
import { BlogEditorPage } from "./pages/BlogEditorPage.tsx" ;
9
- import { Header , PrimaryNav , Grid , GridContainer , Title , } from "@trussworks/react-uswds" ;
9
+ import { Header , PrimaryNav , Grid , GridContainer } from "@trussworks/react-uswds" ;
10
10
import { HomePage } from "./pages/HomePage.tsx" ;
11
11
import { AboutPage } from "./pages/AboutPage.tsx" ;
12
12
@@ -23,7 +23,12 @@ type PagesMap = {
23
23
24
24
25
25
function App ( ) {
26
- const [ page , SetPage ] = useState < PagesType > ( "Home" ) ;
26
+ // this is basically useState that persists to localstorage
27
+ const [ page , setPage ] = useReducer ( ( _prev : PagesType , cur : PagesType ) => {
28
+ localStorage . setItem ( 'currentPage' , cur ) ;
29
+ return cur ;
30
+ } , ( localStorage . getItem ( 'currentPage' ) as PagesType ) || "Home" ) ;
31
+
27
32
const PAGES_MAP : PagesMap = {
28
33
"Home" : < HomePage /> ,
29
34
"Blog Edit" : < BlogEditorPage /> ,
@@ -34,7 +39,8 @@ function App() {
34
39
< Fragment >
35
40
< Header basic >
36
41
< div className = { "float-left position-absolute top-1 left-105 text-bold" } >
37
- Website Content Editor</ div >
42
+ Website Content Editor
43
+ </ div >
38
44
< div className = "usa-nav-container" >
39
45
< PrimaryNav
40
46
aria-label = "Primary navigation"
@@ -43,7 +49,7 @@ function App() {
43
49
href = ""
44
50
className = { eachPage === page ? "usa-nav__link usa-current" : "usa-nav__link" }
45
51
onClick = { ( e ) => {
46
- SetPage ( eachPage ) ;
52
+ setPage ( eachPage ) ;
47
53
e . preventDefault ( ) ;
48
54
e . stopPropagation ( ) ;
49
55
} } > { eachPage } </ a > ) } />
@@ -57,7 +63,7 @@ function App() {
57
63
id = "main-content"
58
64
role = { "main" }
59
65
>
60
- { PAGES_MAP [ page ] }
66
+ { PAGES_MAP [ page ] ?? PAGES_MAP . Home }
61
67
</ main >
62
68
</ Grid >
63
69
</ GridContainer >
0 commit comments