From 77622225b4ac952f175c7ade00e7f56fd75a31e3 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 9 Mar 2020 16:39:00 +0100 Subject: [PATCH] Split chain logo/info away from SideBar (#2356) --- packages/apps/src/Apps.tsx | 40 ++++------ packages/apps/src/SideBar/ChainInfo.tsx | 78 +++++++++++++++++++ packages/apps/src/SideBar/index.tsx | 55 +------------ packages/apps/src/WarmUp.tsx | 23 ++++++ packages/react-components/src/styles/index.ts | 4 + 5 files changed, 121 insertions(+), 79 deletions(-) create mode 100644 packages/apps/src/SideBar/ChainInfo.tsx create mode 100644 packages/apps/src/WarmUp.tsx diff --git a/packages/apps/src/Apps.tsx b/packages/apps/src/Apps.tsx index 8492b7b592..cd889f1155 100644 --- a/packages/apps/src/Apps.tsx +++ b/packages/apps/src/Apps.tsx @@ -4,12 +4,12 @@ import { BareProps as Props } from '@polkadot/react-components/types'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useMemo, useState } from 'react'; import store from 'store'; import styled from 'styled-components'; import { defaultColor, chainColors, emptyColor, nodeColors } from '@polkadot/apps-config/ui/general'; import GlobalStyle from '@polkadot/react-components/styles'; -import { useApi, useCall } from '@polkadot/react-hooks'; +import { useApi } from '@polkadot/react-hooks'; import Signer from '@polkadot/react-signer'; import AccountsOverlay from './overlays/Accounts'; @@ -17,6 +17,7 @@ import ConnectingOverlay from './overlays/Connecting'; import { SideBarTransition, SIDEBAR_MENU_THRESHOLD } from './constants'; import Content from './Content'; import SideBar from './SideBar'; +import WarmUp from './WarmUp'; interface SidebarState { isCollapsed: boolean; @@ -31,23 +32,6 @@ function sanitize (value?: string): string { return value?.toLowerCase().replace('-', ' ') || ''; } -function WarmUp (): React.ReactElement { - const { api, isApiReady } = useApi(); - const fees = useCall(isApiReady ? api.derive.balances?.fees : undefined, []); - const indexes = useCall(isApiReady ? api.derive.accounts?.indexes : undefined, []); - const registrars = useCall(isApiReady ? api.query.identity?.registrars : undefined, []); - const staking = useCall(isApiReady ? api.derive.staking?.overview : undefined, []); - const [hasValues, setHasValues] = useState(false); - - useEffect((): void => { - setHasValues(!!fees || !!indexes || !!registrars || !!staking); - }, []); - - return ( -
- ); -} - function Apps ({ className }: Props): React.ReactElement { const { systemChain, systemName } = useApi(); const [sidebar, setSidebar] = useState({ @@ -159,16 +143,18 @@ export default styled(Apps)` } .apps--SideBar-logo { - margin: 0.875rem auto; - padding: 0; - width: 3rem; + .apps--SideBar-logo-inner { + margin: auto; + padding: 0; + width: 3rem; - img { - margin: 0 0.25rem 0 0; - } + img { + margin: 0 0.4rem; + } - > div.info { - display: none; + > div.info { + display: none; + } } } diff --git a/packages/apps/src/SideBar/ChainInfo.tsx b/packages/apps/src/SideBar/ChainInfo.tsx new file mode 100644 index 0000000000..5f6e513564 --- /dev/null +++ b/packages/apps/src/SideBar/ChainInfo.tsx @@ -0,0 +1,78 @@ +// Copyright 2017-2020 @polkadot/apps authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { RuntimeVersion } from '@polkadot/types/interfaces'; + +import React from 'react'; +import styled from 'styled-components'; +import { ChainImg } from '@polkadot/react-components'; +import { useCall, useApi } from '@polkadot/react-hooks'; +import { BestNumber, Chain } from '@polkadot/react-query'; + +import { useTranslation } from '../translate'; + +interface Props { + className?: string; + onClick?: () => void; +} + +function ChainInfo ({ className, onClick }: Props): React.ReactElement { + const { t } = useTranslation(); + const { api } = useApi(); + const runtimeVersion = useCall(api.rpc.state.subscribeRuntimeVersion, []); + + return ( +
+
+ +
+ + {runtimeVersion && ( +
{t('version {{version}}', { replace: { version: runtimeVersion.specVersion.toNumber() } })}
+ )} + +
+
+
+ ); +} + +export default styled(ChainInfo)` + border-top: 0.5rem solid transparent; + cursor: pointer; + padding: 0.75rem 1rem; + margin: 0 0 0.5rem -0.75rem; + + .apps--SideBar-logo-inner { + display: flex; + align-items: center; + justify-content: space-between; + width: 10rem; + + img { + height: 2.75rem; + width: 2.75rem; + } + + > div.info { + color: white; + opacity: 0.75; + text-align: right; + vertical-align: middle; + + > div.chain { + font-size: 0.9rem; + line-height: 1rem; + } + + > div.runtimeVersion { + font-size: 0.75rem; + line-height: 1rem; + } + } + } +`; diff --git a/packages/apps/src/SideBar/index.tsx b/packages/apps/src/SideBar/index.tsx index 7c8c916678..27eeb1e781 100644 --- a/packages/apps/src/SideBar/index.tsx +++ b/packages/apps/src/SideBar/index.tsx @@ -2,7 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { RuntimeVersion } from '@polkadot/types/interfaces'; import { SIDEBAR_MENU_THRESHOLD } from '../constants'; import React, { useState } from 'react'; @@ -10,14 +9,13 @@ import styled from 'styled-components'; import { Responsive } from 'semantic-ui-react'; import routing from '@polkadot/apps-routing'; import { Button, ChainImg, Icon, Menu, media } from '@polkadot/react-components'; -import { useCall, useApi } from '@polkadot/react-hooks'; import { classes } from '@polkadot/react-components/util'; -import { BestNumber, Chain } from '@polkadot/react-query'; +import NetworkModal from '../modals/Network'; import { useTranslation } from '../translate'; +import ChainInfo from './ChainInfo'; import Item from './Item'; import NodeInfo from './NodeInfo'; -import NetworkModal from '../modals/Network'; interface Props { className?: string; @@ -30,8 +28,6 @@ interface Props { function SideBar ({ className, collapse, handleResize, isCollapsed, isMenuOpen, toggleMenu }: Props): React.ReactElement { const { t } = useTranslation(); - const { api } = useApi(); - const runtimeVersion = useCall(api.rpc.state.subscribeRuntimeVersion, []); const [modals, setModals] = useState>( routing.routes.reduce((result: Record, route): Record => { if (route && route.Modal) { @@ -70,25 +66,12 @@ function SideBar ({ className, collapse, handleResize, isCollapsed, isMenuOpen, )}
-
-
- -
- - {runtimeVersion && ( -
{t('version {{version}}', { replace: { version: runtimeVersion.specVersion.toNumber() } })}
- )} - -
-
+ {routing.routes.map((route, index): React.ReactNode => ( route ? ( @@ -231,38 +214,6 @@ export default styled(SideBar)` } } - .apps--SideBar-logo { - cursor: pointer; - display: flex; - align-items: center; - justify-content: space-between; - margin: 0.5rem 1rem 1.5rem 0; - padding-top: 0.75em; - width: 10rem; - - img { - height: 2.75rem; - width: 2.75rem; - } - - > div.info { - color: white; - opacity: 0.75; - text-align: right; - vertical-align: middle; - - > div.chain { - font-size: 0.9rem; - line-height: 1rem; - } - - > div.runtimeVersion { - font-size: 0.75rem; - line-height: 1rem; - } - } - } - .apps--SideBar-collapse { background: #4f4f4f; bottom: 0; diff --git a/packages/apps/src/WarmUp.tsx b/packages/apps/src/WarmUp.tsx new file mode 100644 index 0000000000..94b1b3c24b --- /dev/null +++ b/packages/apps/src/WarmUp.tsx @@ -0,0 +1,23 @@ +// Copyright 2017-2020 @polkadot/apps authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import React, { useEffect, useState } from 'react'; +import { useApi, useCall } from '@polkadot/react-hooks'; + +export default function WarmUp (): React.ReactElement { + const { api, isApiReady } = useApi(); + const fees = useCall(isApiReady ? api.derive.balances?.fees : undefined, []); + const indexes = useCall(isApiReady ? api.derive.accounts?.indexes : undefined, []); + const registrars = useCall(isApiReady ? api.query.identity?.registrars : undefined, []); + const staking = useCall(isApiReady ? api.derive.staking?.overview : undefined, []); + const [hasValues, setHasValues] = useState(false); + + useEffect((): void => { + setHasValues(!!fees || !!indexes || !!registrars || !!staking); + }, []); + + return ( +
+ ); +} diff --git a/packages/react-components/src/styles/index.ts b/packages/react-components/src/styles/index.ts index b2a9b05b61..932af0a051 100644 --- a/packages/react-components/src/styles/index.ts +++ b/packages/react-components/src/styles/index.ts @@ -37,6 +37,10 @@ export default createGlobalStyle` color: ${(props): string => (props.uiHighlight || '#999')} !important; } + .ui--highlight--gradient { + background: ${(props): string => `linear-gradient(90deg, ${props.uiHighlight}, transparent)`}; + } + #root { color: #4e4e4e; font-family: sans-serif;