From 65bf6539d73ea79f7a209e8117e291a692770cbe Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 17 Oct 2021 02:07:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20BreadcrumbsBox=20for=20naviga?= =?UTF-8?q?tion=20(closes=20#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 2 + frontend/src/components/elements/Link.tsx | 16 +++-- .../src/components/routing/BreadcrumbLink.tsx | 22 ++++++ .../routing/BreadcrumbSeparator.tsx | 12 ++++ .../src/components/routing/BreadcrumbsBox.tsx | 72 +++++++++++++++++++ 5 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 frontend/src/components/routing/BreadcrumbLink.tsx create mode 100644 frontend/src/components/routing/BreadcrumbSeparator.tsx create mode 100644 frontend/src/components/routing/BreadcrumbsBox.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f961491..060cf94 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -23,6 +23,7 @@ import {NotebookRouter} from "./components/notebook/NotebookRouter" import {ProjectCreateBox} from "./components/project/ProjectCreateBox" import {ProjectListBox} from "./components/project/ProjectListBox" import {ProjectRouter} from "./components/project/ProjectRouter" +import {BreadcrumbsBox} from "./components/routing/BreadcrumbsBox" import {ThemedBluelib} from "./components/theme/ThemedBluelib" import {ThemedTitle} from "./components/theme/ThemedTitle" import {AuthorizationProvider} from "./contexts/authorization" @@ -41,6 +42,7 @@ function App({..._}: RouteComponentProps) { + diff --git a/frontend/src/components/elements/Link.tsx b/frontend/src/components/elements/Link.tsx index 853f7c9..22f164e 100644 --- a/frontend/src/components/elements/Link.tsx +++ b/frontend/src/components/elements/Link.tsx @@ -1,7 +1,7 @@ -import * as React from "react" import * as Reach from "@reach/router" -import {Anchor, BringAttention as B} from "@steffo/bluelib-react"; -import {AnchorProps} from "@steffo/bluelib-react/dist/components/common/Anchor"; +import {Anchor, BringAttention as B} from "@steffo/bluelib-react" +import {AnchorProps} from "@steffo/bluelib-react/dist/components/common/Anchor" +import * as React from "react" /** @@ -18,19 +18,21 @@ export function Link({href, children, onClick, ...props}: AnchorProps): JSX.Elem if (onClick) { onClick(event) } - if (href) { + if(href) { // noinspection JSIgnoredPromiseFromCall Reach.navigate(href) } }, - [href, onClick] + [href, onClick], ) - if (location.pathname === href) { + // FIXME: Shenanigans? + if(location.pathname.replace("%25", "%") === href) { return ( ) - } else { + } + else { return ( ) diff --git a/frontend/src/components/routing/BreadcrumbLink.tsx b/frontend/src/components/routing/BreadcrumbLink.tsx new file mode 100644 index 0000000..dbcbeaa --- /dev/null +++ b/frontend/src/components/routing/BreadcrumbLink.tsx @@ -0,0 +1,22 @@ +import {IconDefinition} from "@fortawesome/fontawesome-svg-core" +import * as React from "react" +import {IconText} from "../elements/IconText" +import {Link} from "../elements/Link" + + +export interface BreadcrumbLinkProps { + href: string, + icon: IconDefinition, + text: string, +} + + +export function BreadcrumbLink({href, icon, text}: BreadcrumbLinkProps): JSX.Element { + return ( + + + {text} + + + ) +} \ No newline at end of file diff --git a/frontend/src/components/routing/BreadcrumbSeparator.tsx b/frontend/src/components/routing/BreadcrumbSeparator.tsx new file mode 100644 index 0000000..5b32a9c --- /dev/null +++ b/frontend/src/components/routing/BreadcrumbSeparator.tsx @@ -0,0 +1,12 @@ +import {faChevronRight} from "@fortawesome/free-solid-svg-icons" +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" +import * as React from "react" + + +export function BreadcrumbSeparator(): JSX.Element { + return <> +   + +   + +} \ No newline at end of file diff --git a/frontend/src/components/routing/BreadcrumbsBox.tsx b/frontend/src/components/routing/BreadcrumbsBox.tsx new file mode 100644 index 0000000..deb830d --- /dev/null +++ b/frontend/src/components/routing/BreadcrumbsBox.tsx @@ -0,0 +1,72 @@ +import {faBook, faProjectDiagram, faServer, faUniversity, faUser, faUsers} from "@fortawesome/free-solid-svg-icons" +import {Box} from "@steffo/bluelib-react" +import * as React from "react" +import {useSophonPath} from "../../hooks/useSophonPath" +import {InstanceEncoder} from "../../utils/InstanceEncoder" +import {BreadcrumbLink} from "./BreadcrumbLink" +import {BreadcrumbSeparator} from "./BreadcrumbSeparator" + + +export function BreadcrumbsBox(): JSX.Element { + const location = useSophonPath() + + return ( + + + {location.instance ? ( + <> + + + {location.loggedIn ? ( + <> + + + {location.researchGroup ? ( + <> + + + {location.researchProject ? ( + <> + + + {location.notebook ? ( + <> + + + + ) : null} + + ) : null} + + ) : null} + + ) : null} + + ) : null} + + ) +}