diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index bc49686..3cf7c3c 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,21 +1,21 @@ import * as React from 'react'; import {LayoutThreeCol} from "@steffo/bluelib-react"; -import {LookAndFeel} from "./components/theme/LookAndFeel"; -import {SophonFooter} from "./components/theme/SophonFooter"; +import {SophonInstanceFooter} from "./components/instance/SophonInstanceFooter"; +import * as Instance from "./components/instance" export default function App() { return ( - - - + + + - - + + - - + + ); } diff --git a/frontend/src/components/instance/Interfaces.ts b/frontend/src/components/instance/Interfaces.ts new file mode 100644 index 0000000..b62ee30 --- /dev/null +++ b/frontend/src/components/instance/Interfaces.ts @@ -0,0 +1,27 @@ +import {SophonInstanceDetails} from "../../utils/SophonTypes"; +import * as React from "react"; + +// This file exists to avoid circular imports. + +/** + * Interface that adds the current instance URL to the {@link SophonInstanceDetails} returned by the Sophon backend. + */ +export interface SophonInstanceState extends SophonInstanceDetails { + url: URL, +} + + +/** + * Interface for the {@link SophonInstanceContext} context that provides a way for consumers to alter the {@link SophonInstanceState}. + */ +export interface SophonInstanceContextData extends SophonInstanceState { + setDetails?: React.Dispatch> +} + + +/** + * Props of the {@link SophonInstanceProvider}. + */ +export interface SophonInstanceProviderProps { + children: React.ReactNode, +} \ No newline at end of file diff --git a/frontend/src/components/instance/SophonInstanceBluelib.tsx b/frontend/src/components/instance/SophonInstanceBluelib.tsx new file mode 100644 index 0000000..64c575c --- /dev/null +++ b/frontend/src/components/instance/SophonInstanceBluelib.tsx @@ -0,0 +1,26 @@ +import * as React from "react" +import {Bluelib} from "@steffo/bluelib-react"; +import {useSophonInstance} from "./useSophonInstance"; + + +export interface SophonInstanceBluelibProps { + children: React.ReactNode, +} + + +/** + * Component which wraps its children in a {@link Bluelib} component with a theme based on its instance. + * + * Defaults to the `"sophon"` theme if no instance is set. + * + * @constructor + */ +export function SophonInstanceBluelib({children}: SophonInstanceBluelibProps): JSX.Element { + const instance = useSophonInstance() + + return ( + + {children} + + ) +} diff --git a/frontend/src/components/instance/SophonInstanceContext.tsx b/frontend/src/components/instance/SophonInstanceContext.tsx new file mode 100644 index 0000000..df6ea15 --- /dev/null +++ b/frontend/src/components/instance/SophonInstanceContext.tsx @@ -0,0 +1,8 @@ +import * as React from "react" +import {SophonInstanceContextData} from "./Interfaces"; + + +/** + * The context that contains all the data about the currently selected Sophon instance. + */ +export const SophonInstanceContext = React.createContext(undefined) diff --git a/frontend/src/components/theme/SophonFooter.tsx b/frontend/src/components/instance/SophonInstanceFooter.tsx similarity index 73% rename from frontend/src/components/theme/SophonFooter.tsx rename to frontend/src/components/instance/SophonInstanceFooter.tsx index 81c3c80..4bb5186 100644 --- a/frontend/src/components/theme/SophonFooter.tsx +++ b/frontend/src/components/instance/SophonInstanceFooter.tsx @@ -1,6 +1,6 @@ import * as React from "react" import {Anchor, Footer} from "@steffo/bluelib-react"; -import {useLookAndFeel} from "./LookAndFeel"; +import {useSophonInstance} from "./useSophonInstance"; const FOOTER_COLORS = { @@ -15,11 +15,8 @@ const BACKEND_REPO_URL = "https://github.com/Steffo99/sophon/tree/main/backend" const LICENSE_URL = "https://github.com/Steffo99/sophon/blob/main/LICENSE.txt" -export function SophonFooter(): JSX.Element { - const lookAndFeel = useLookAndFeel() - - const frontendVersion = process.env.REACT_APP_VERSION - const backendVersion = lookAndFeel.backendVersion +export function SophonInstanceFooter(): JSX.Element { + const instance = useSophonInstance() return (