forked from local-resilience-tech/site-manager
-
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
1 parent
a9e3787
commit 0b61fd3
Showing
6 changed files
with
76 additions
and
136 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
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 +1 @@ | ||
export { default as ThisRegion } from "./pages/ThisRegion" | ||
export { default as EnsureRegion } from "./pages/EnsureRegion" |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as ThisSite } from "./pages/ThisSite" | ||
export { default as EnsureSite } from "./pages/EnsureSite" | ||
export { default as ThisNode } from "./pages/ThisNode" |
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,69 @@ | ||
import { Center, Container, Spinner } from "@chakra-ui/react" | ||
import { useEffect, useState } from "react" | ||
import NewSite, { NewSiteData } from "../components/NewSite" | ||
import { SiteDetails } from "../types" | ||
import ThisSiteApi from "../api" | ||
import { ApiResult } from "../../shared/types" | ||
|
||
const api = new ThisSiteApi() | ||
|
||
const getSite = async (): Promise<SiteDetails | null> => { | ||
const result = await api.show() | ||
if ("Ok" in result) return result.Ok | ||
return null | ||
} | ||
|
||
export default function EnsureSite() { | ||
const [site, setSite] = useState<SiteDetails | null>(null) | ||
const [loading, setLoading] = useState(true) | ||
|
||
const updateSite = (newSite: SiteDetails | null) => { | ||
console.log("Updating site", newSite) | ||
setSite(newSite) | ||
} | ||
|
||
const withLoading = async (fn: () => Promise<void>) => { | ||
setLoading(true) | ||
await fn() | ||
setLoading(false) | ||
} | ||
|
||
const fetchSite = async () => { | ||
withLoading(async () => { | ||
console.log("EFFECT: fetchSite") | ||
const newSite = await getSite() | ||
updateSite(newSite) }) | ||
} | ||
|
||
useEffect(() => { | ||
if (site == null) fetchSite() | ||
}, []) | ||
|
||
const onSubmitNewSite = (data: NewSiteData) => { | ||
api.create(data.name).then((result: ApiResult<SiteDetails, any>) => { | ||
if ("Ok" in result) updateSite(result.Ok) | ||
}) | ||
} | ||
|
||
if (loading) { | ||
return ( | ||
<Container maxWidth={"2xl"}> | ||
<Center> | ||
<Spinner size="lg" opacity={0.5} /> | ||
</Center> | ||
</Container> | ||
) | ||
} | ||
|
||
return ( | ||
<Container maxWidth={"2xl"}> | ||
{site == null && <NewSite onSubmitNewSite={onSubmitNewSite} />} | ||
{site != null && ( | ||
<div> | ||
<h1>Site created!</h1> | ||
<p>Site: {site?.name}</p> | ||
</div> | ||
)} | ||
</Container> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.