-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
import { useState } from "preact/hooks"; | ||
|
||
import "./app.css"; | ||
|
||
import TLP from "./pages/tlp"; | ||
import LHTLP from "./pages/lhtlp"; | ||
import Index from "./pages/index"; | ||
import { LHTLP_PATH, ROOT_PATH, TLP_PATH } from "./constants"; | ||
import Nav from "./components/Nav"; | ||
import { LHTLP_PATH, TLP_PATH } from "./constants"; | ||
import { SharedStateProvider, useSharedState } from "./components/SharedState"; | ||
|
||
export function App() { | ||
const [path, setPath] = useState(ROOT_PATH); | ||
return ( | ||
<SharedStateProvider> | ||
<Page /> | ||
</SharedStateProvider> | ||
); | ||
} | ||
|
||
function Page() { | ||
const { path } = useSharedState(); | ||
|
||
let page = <Index />; | ||
|
||
if (path === TLP_PATH) { | ||
return <TLP path={path} setPath={setPath} />; | ||
page = <TLP />; | ||
} else if (path === LHTLP_PATH) { | ||
return <LHTLP path={path} setPath={setPath} />; | ||
page = <LHTLP />; | ||
} | ||
|
||
return <Index path={path} setPath={setPath} />; | ||
return ( | ||
<> | ||
<Nav /> | ||
<hr /> | ||
{page} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// See: https://kentcdodds.com/blog/application-state-management-with-react | ||
|
||
import { createContext } from "preact"; | ||
import { useContext, useState } from "preact/hooks"; | ||
|
||
import { ROOT_PATH } from "../constants"; | ||
|
||
const SharedStateContext = createContext(); | ||
|
||
export function useSharedState() { | ||
const context = useContext(SharedStateContext); | ||
|
||
if (!context) { | ||
throw new Error("useSharedState must be used within a SharedStateProvider"); | ||
} | ||
|
||
return context; | ||
} | ||
|
||
export function SharedStateProvider(props) { | ||
const { children } = props; | ||
const [path, setPath] = useState(ROOT_PATH); | ||
|
||
return ( | ||
<SharedStateContext.Provider | ||
value={{ | ||
path, | ||
setPath, | ||
}} | ||
> | ||
{children} | ||
</SharedStateContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters