import * as React from "react"; import Linkify from "linkify-react"; import styled from "styled-components"; import { Box, Flex, Text } from "rimble-ui"; import { OpenInNew } from "@rimble/icons"; import { H5 } from "../../layouts"; import { baseColors, colors } from "../../../themes"; import { SchemaDataResponse, SchemaDataInput } from "./types"; import { SchemaSaves } from "./SchemaSaves"; import { SchemaHeader } from "./SchemaHeader"; import { SchemaPreview, SchemaViewTypes, SCHEMA_VIEWS } from "./SchemaPreview"; import { GitHub } from "../../elements/Icons/GitHub"; import { SertoUiContext, SertoUiContextInterface } from "../../../context/SertoUiContext"; const SidebarHeading = styled(H5)` margin-bottom: 12px; &:first-child { margin-top: 0; } `; const UserLink = styled.a` color: ${baseColors.blurple}; text-decoration: none; &:hover { color: ${colors.primary.light}; } &, svg { vertical-align: middle; } svg { margin: 0 8px; } svg:first-child { margin-left: 0; } `; export interface SchemaDetailProps { schema: SchemaDataInput | SchemaDataResponse; primaryView?: SchemaViewTypes; /** Whether to show various tools including "save" and "issue VC" functionality. */ hideTools?: boolean; /** Whether to show "issue VC" functionality. */ hideIssueVc?: boolean; /** Some layout changes in pane view: the header is pushed inside and below the view switcher dropdown, and only shown in non-JSON view. */ paneView?: boolean; noSwitcher?: boolean; fullPage?: boolean; } export const SchemaDetail: React.FunctionComponent = (props) => { const { schema, primaryView, hideTools, hideIssueVc, fullPage, paneView, noSwitcher } = props; const schemasService = React.useContext(SertoUiContext).schemasService; const [view, setView] = React.useState(primaryView || SCHEMA_VIEWS[0]); const userOwnsSchema = "creator" in schema && schemasService.userData?.sub === schema.creator?.identifier; // If `primaryView` prop changes, set the view to that - but future calls to `setView` will still take effect. React.useEffect(() => { if (primaryView) { setView(primaryView); } }, [primaryView]); return ( <> {/* {!paneView && ( {!hideTools && } )} */} {fullPage && ( Description {schema.description} Schema Author {"creator" in schema && schema.creator?.name && schema.creator.nickName ? ( <> {schema.creator.name && ( {schema.creator.name} {userOwnsSchema && " (you)"} )} {schema.creator.identifier.includes("github") && ( {schema.creator.nickName} )} ) : ( Author details coming soon )} {"updated" in schema && ( <> Releases Version {schema.version} on {new Date(schema.updated).toLocaleDateString()} Full version history coming soon )} )} ); };