diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d72644d..717713a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,7 +1,8 @@ import * as React from 'react'; -import {Bluelib, Box, Heading, LayoutThreeCol} from "@steffo/bluelib-react"; +import {Bluelib, Chapter, Heading, LayoutThreeCol} from "@steffo/bluelib-react"; import {SophonContextProvider} from "./utils/SophonContext"; import {LoginBox} from "./components/LoginBox"; +import {InstanceBox} from "./components/InstanceBox"; function App() { return ( @@ -12,7 +13,10 @@ function App() { Sophon - + + + + diff --git a/frontend/src/components/InstanceBox.tsx b/frontend/src/components/InstanceBox.tsx new file mode 100644 index 0000000..3238d0e --- /dev/null +++ b/frontend/src/components/InstanceBox.tsx @@ -0,0 +1,52 @@ +import * as React from "react" +import * as ReactDOM from "react-dom" +import {Box, Heading, Form, Anchor} from "@steffo/bluelib-react"; +import {useSophonContext} from "../utils/SophonContext"; +import {useFormProps} from "../hooks/useValidatedState"; + + +interface InstanceBoxProps { + +} + + +export function InstanceBox({}: InstanceBoxProps): JSX.Element { + const {instanceUrl, changeSophon} = useSophonContext() + const sophonServer = useFormProps("", value => { + if(value === "") return null + + try { + new URL(value) + } catch (_) { + return false + } + + return true + }) + + const doChange = React.useCallback( + () => { + changeSophon(sophonServer.value.trim()) + // Small hack to clear the field + sophonServer.onSimpleChange("") + }, + [changeSophon, sophonServer] + ) + + return ( + + + Change instance + +

+ You are currently using the Sophon instance at {instanceUrl}. +

+
+ + + Change instance + + +
+ ) +} diff --git a/frontend/src/utils/SophonContext.tsx b/frontend/src/utils/SophonContext.tsx index 3cf4383..8c1def8 100644 --- a/frontend/src/utils/SophonContext.tsx +++ b/frontend/src/utils/SophonContext.tsx @@ -55,6 +55,11 @@ export interface SophonContextContents { */ logout: LogoutFunction, + /** + * The Sophon instance URL. + */ + instanceUrl: string, + /** * Change Sophon instance to the one with the given `url`. */ @@ -156,7 +161,7 @@ export function SophonContextProvider({children}: SophonContextProviderProps): J ) return ( - + {children} )