From a7eb7a78b472b0620713bcc7094c1e7b9f43b5d9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 7 Oct 2021 02:36:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20`GroupListBox`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 5 +- .../src/components/group/GroupListBox.tsx | 22 ++++++ .../components/group/GroupResourcePanel.tsx | 37 +++++++++ frontend/src/contexts/group.tsx | 79 +++++++++++++++++++ 4 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/group/GroupListBox.tsx create mode 100644 frontend/src/components/group/GroupResourcePanel.tsx create mode 100644 frontend/src/contexts/group.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a6d91fa..cd8510e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,6 +6,7 @@ import {AuthorizationRouter} from "./components/authorization/AuthorizationRoute import {AuthorizationStepPage} from "./components/authorization/AuthorizationStepPage" import {SophonFooter} from "./components/elements/SophonFooter" import {ErrorCatcherBox} from "./components/errors/ErrorCatcherBox" +import {GroupListBox} from "./components/group/GroupListBox" import {GroupRouter} from "./components/group/GroupRouter" import {InstanceRouter} from "./components/instance/InstanceRouter" import {InstanceStepPage} from "./components/instance/InstanceStepPage" @@ -17,7 +18,7 @@ import {InstanceProvider} from "./contexts/instance" import {ThemeProvider} from "./contexts/theme" -function App({...props}: RouteComponentProps) { +function App({}: RouteComponentProps) { return ( } selectedRoute={() => <> } selectedRoute={DebugBox} /> } diff --git a/frontend/src/components/group/GroupListBox.tsx b/frontend/src/components/group/GroupListBox.tsx new file mode 100644 index 0000000..822db66 --- /dev/null +++ b/frontend/src/components/group/GroupListBox.tsx @@ -0,0 +1,22 @@ +import {Box, Heading} from "@steffo/bluelib-react" +import * as React from "react" +import {SophonResearchGroup} from "../../types/SophonTypes" +import {ListRouteProps} from "../routing/ViewSetRouter" +import {GroupResourcePanel} from "./GroupResourcePanel" + + +export interface GroupListBoxProps extends ListRouteProps { + +} + + +export function GroupListBox({viewSet}: GroupListBoxProps): JSX.Element { + return ( + + + Research groups + + {viewSet.resources?.map(res => )} + + ) +} diff --git a/frontend/src/components/group/GroupResourcePanel.tsx b/frontend/src/components/group/GroupResourcePanel.tsx new file mode 100644 index 0000000..de11059 --- /dev/null +++ b/frontend/src/components/group/GroupResourcePanel.tsx @@ -0,0 +1,37 @@ +import {faEnvelope, faGlobe} from "@fortawesome/free-solid-svg-icons" +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" +import * as React from "react" +import {ManagedResource} from "../../hooks/useManagedViewSet" +import {SophonResearchGroup} from "../../types/SophonTypes" +import {Link} from "../elements/Link" +import {ResourcePanel} from "../elements/ResourcePanel" + + +export interface GroupResourcePanelProps { + resource: ManagedResource, +} + + +export function GroupResourcePanel({resource}: GroupResourcePanelProps): JSX.Element { + const icon = resource.value.access === "OPEN" ? faGlobe : faEnvelope + const members = resource.value.members.length + + return ( + + + + + + + {resource.value.name} + + + + {members} member{members !== 1 ? "s" : ""} + + + + + + ) +} diff --git a/frontend/src/contexts/group.tsx b/frontend/src/contexts/group.tsx new file mode 100644 index 0000000..fd339b9 --- /dev/null +++ b/frontend/src/contexts/group.tsx @@ -0,0 +1,79 @@ +import * as React from "react" +import {ContextData} from "../types/ContextTypes" +import {WithChildren} from "../types/ExtraTypes" + +// States + +type GroupSelected = { + bluelib: "sophon" | "royalblue" | "hacker" | "paper", + title: string, +} + + +// Actions + +type GroupSet = { + type: "set", + bluelib: "sophon" | "royalblue" | "hacker" | "paper", + title: string, +} + +type GroupReset = { + type: "reset", +} + + +// Composition + +export type GroupState = GroupSelected +type GroupAction = GroupSet | GroupReset +export type GroupContextData = ContextData | undefined + + +// Definitions + +const groupDefaultState: GroupState = { + bluelib: "sophon", + title: "Sophon", +} + +const groupReducer: React.Reducer = (prevState, action) => { + switch(action.type) { + case "set": + // Bail out if trying to set to the same state as earlier + if(prevState.bluelib === action.bluelib && prevState.title === action.title) { + return prevState + } + + return { + bluelib: action.bluelib, + title: action.title, + } + case "reset": + return groupDefaultState + } +} + +const groupContext = React.createContext(undefined) +const GroupContext = groupContext + + +// Hooks + +export function useGroupReducer(): GroupContextData { + const [state, dispatch] = React.useReducer(groupReducer, groupDefaultState) + return {state, dispatch} +} + +export function useGroupContext(): GroupContextData { + return React.useContext(groupContext) +} + + +// Components + +export function GroupProvider({children}: WithChildren): JSX.Element { + const reducer = useGroupReducer() + + return +} \ No newline at end of file