From 0085559ac9dd11854b8e1479db08c437cfb91880 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 30 Sep 2021 03:57:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20Develop=20the=20"SophonInstance"?= =?UTF-8?q?=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 18 ++--- .../src/components/instance/Interfaces.ts | 27 +++++++ .../instance/SophonInstanceBluelib.tsx | 26 +++++++ .../instance/SophonInstanceContext.tsx | 8 +++ .../SophonInstanceFooter.tsx} | 13 ++-- .../instance/SophonInstanceHeading.tsx | 26 +++++++ .../instance/SophonInstancePageTitle.tsx | 25 +++++++ .../instance/SophonInstancePickerBox.tsx | 71 +++++++++++++++++++ .../instance/SophonInstanceProvider.tsx | 20 ++++++ frontend/src/components/instance/index.ts | 9 +++ .../src/components/instance/useSophonAxios.ts | 25 +++++++ .../components/instance/useSophonInstance.ts | 11 +++ frontend/src/components/theme/LookAndFeel.tsx | 61 ---------------- .../components/theme/LookAndFeelBluelib.tsx | 19 ----- .../components/theme/LookAndFeelHeading.tsx | 20 ------ .../components/theme/LookAndFeelPageTitle.tsx | 16 ----- 16 files changed, 262 insertions(+), 133 deletions(-) create mode 100644 frontend/src/components/instance/Interfaces.ts create mode 100644 frontend/src/components/instance/SophonInstanceBluelib.tsx create mode 100644 frontend/src/components/instance/SophonInstanceContext.tsx rename frontend/src/components/{theme/SophonFooter.tsx => instance/SophonInstanceFooter.tsx} (73%) create mode 100644 frontend/src/components/instance/SophonInstanceHeading.tsx create mode 100644 frontend/src/components/instance/SophonInstancePageTitle.tsx create mode 100644 frontend/src/components/instance/SophonInstancePickerBox.tsx create mode 100644 frontend/src/components/instance/SophonInstanceProvider.tsx create mode 100644 frontend/src/components/instance/index.ts create mode 100644 frontend/src/components/instance/useSophonAxios.ts create mode 100644 frontend/src/components/instance/useSophonInstance.ts delete mode 100644 frontend/src/components/theme/LookAndFeel.tsx delete mode 100644 frontend/src/components/theme/LookAndFeelBluelib.tsx delete mode 100644 frontend/src/components/theme/LookAndFeelHeading.tsx delete mode 100644 frontend/src/components/theme/LookAndFeelPageTitle.tsx 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 (