Skip to content

Commit d8458ce

Browse files
committed
Reloading site persists "current page"
1 parent 4adcfdd commit d8458ce

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/App.css

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@
4646
.zoom-066 {
4747
zoom: 0.667;
4848
}
49+

src/App.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import '@mdxeditor/editor/style.css';
44
import './styles/usdswebsite.override.css';
55
import "react-toastify/dist/ReactToastify.css";
66
import "./App.css";
7-
import {Fragment, useState} from "react";
7+
import {Fragment, useReducer} from "react";
88
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";
1010
import {HomePage} from "./pages/HomePage.tsx";
1111
import {AboutPage} from "./pages/AboutPage.tsx";
1212

@@ -23,7 +23,12 @@ type PagesMap = {
2323

2424

2525
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+
2732
const PAGES_MAP: PagesMap = {
2833
"Home": <HomePage/>,
2934
"Blog Edit": <BlogEditorPage/>,
@@ -34,7 +39,8 @@ function App() {
3439
<Fragment>
3540
<Header basic>
3641
<div className={"float-left position-absolute top-1 left-105 text-bold"}>
37-
Website Content Editor</div>
42+
Website Content Editor
43+
</div>
3844
<div className="usa-nav-container">
3945
<PrimaryNav
4046
aria-label="Primary navigation"
@@ -43,7 +49,7 @@ function App() {
4349
href=""
4450
className={eachPage === page ? "usa-nav__link usa-current" : "usa-nav__link"}
4551
onClick={(e) => {
46-
SetPage(eachPage);
52+
setPage(eachPage);
4753
e.preventDefault();
4854
e.stopPropagation();
4955
}}>{eachPage}</a>)}/>
@@ -57,7 +63,7 @@ function App() {
5763
id="main-content"
5864
role={"main"}
5965
>
60-
{PAGES_MAP[page]}
66+
{PAGES_MAP[page] ?? PAGES_MAP.Home}
6167
</main>
6268
</Grid>
6369
</GridContainer>

src/components/EditActionsToolbar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const EditActionsToolbar = (props: {
3333
const cleanmdtext = mdtext.replace(`<[email protected]>`, '[email protected]');
3434
props.mdxeditorref?.current?.setMarkdown(cleanmdtext);
3535
localStorage.setItem(MARKDOWN_LOCAL_STORAGE_KEY, mdtext);
36-
setTimeout(() => {
37-
window.location.reload(); // needs some help loading cached images
38-
}, 250);
36+
// setTimeout(() => {
37+
// window.location.reload(); // needs some help loading cached images
38+
// }, 250);
3939
// todo: go through images and see what's missing from cache and prompt for files
4040
}
4141

src/pages/HomePage.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import {Fragment} from "react";
33
export const HomePage = () => {
44
return (<Fragment>
55
<p className="usa-intro">
6-
This site is static only and <strong>all data</strong> is saved into your local browser.
6+
This site is static-only and <strong>all data</strong> is saved into your local browser.
77
</p>
88
<p>
9-
Build website posts with fewer mistakes. The intuitive rich text editor lets you see exactly
10-
how your page will look as you create it. Save your work anytime by downloading a zip file
11-
containing your edits and all associated images.
9+
Build website posts with fewer mistakes. The intuitive rich text editor lets you see
10+
how your page will look as you create it. Your work is saved into the browser’s cache and
11+
you can download a zip file containing your edits and all associated images allow you
12+
to submit them into Github using Github Desktop.
1213
</p>
1314

1415
<p><strong>Click <i>Blog Edit</i> in the top nav to begin.</strong></p>
@@ -20,12 +21,11 @@ export const HomePage = () => {
2021
the most handy.
2122
</p>
2223
<ul>
23-
<li>Crabby will display the page meta information (aka "Frontmatter yaml header" in technobabel) as guided form,
24-
to help
25-
you avoid common mistakes.
24+
<li>Crabby will display the page meta information (aka "Frontmatter yaml header" in technobabel)
25+
as guided input form to help you avoid common mistakes.
2626
</li>
27-
<li>Inserting images will display them in the page and save them when you Download the results.
28-
For best results, correctly size images outside before uploading and use .jpg for faster rendering.
27+
<li>Inserting images will display them in the page and they will appear in the correct locations
28+
when you Download the results.
2929
</li>
3030
<li>The buttons on the right toggle between Markdown and Rich Text views.</li>
3131
</ul>
@@ -43,6 +43,8 @@ export const HomePage = () => {
4343
</p>
4444
<h2 id="section-heading-3">Tips and tricks</h2>
4545
<ul>
46+
<li>For best results, correctly size images before uploading.</li>
47+
<li>Keep image the filesizes small for faster rendering. .jpg with higher compression is recommended.</li>
4648
<li>Paste in rich text directly into the editor and let it reformat it as markdown. It can include images.</li>
4749
<li>Open an existing post’s markdown file.</li>
4850
<li>Paste in existing MD into the Markdown editor view including the yaml header.</li>

0 commit comments

Comments
 (0)