Split chain logo/info away from SideBar (#2356)
This commit is contained in:
parent
f59cd645c0
commit
77622225b4
@ -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<any>(isApiReady ? api.derive.balances?.fees : undefined, []);
|
||||
const indexes = useCall<any>(isApiReady ? api.derive.accounts?.indexes : undefined, []);
|
||||
const registrars = useCall<any>(isApiReady ? api.query.identity?.registrars : undefined, []);
|
||||
const staking = useCall<any>(isApiReady ? api.derive.staking?.overview : undefined, []);
|
||||
const [hasValues, setHasValues] = useState(false);
|
||||
|
||||
useEffect((): void => {
|
||||
setHasValues(!!fees || !!indexes || !!registrars || !!staking);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={`apps--api-warm ${hasValues}`} />
|
||||
);
|
||||
}
|
||||
|
||||
function Apps ({ className }: Props): React.ReactElement<Props> {
|
||||
const { systemChain, systemName } = useApi();
|
||||
const [sidebar, setSidebar] = useState<SidebarState>({
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
78
packages/apps/src/SideBar/ChainInfo.tsx
Normal file
78
packages/apps/src/SideBar/ChainInfo.tsx
Normal file
@ -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<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const runtimeVersion = useCall<RuntimeVersion>(api.rpc.state.subscribeRuntimeVersion, []);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`apps--SideBar-logo ${className} ui--highlight--border`}
|
||||
onClick={onClick}
|
||||
>
|
||||
<div className='apps--SideBar-logo-inner'>
|
||||
<ChainImg />
|
||||
<div className='info'>
|
||||
<Chain className='chain' />
|
||||
{runtimeVersion && (
|
||||
<div className='runtimeVersion'>{t('version {{version}}', { replace: { version: runtimeVersion.specVersion.toNumber() } })}</div>
|
||||
)}
|
||||
<BestNumber label='#' />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -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<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const runtimeVersion = useCall<RuntimeVersion>(api.rpc.state.subscribeRuntimeVersion, []);
|
||||
const [modals, setModals] = useState<Record<string, boolean>>(
|
||||
routing.routes.reduce((result: Record<string, boolean>, route): Record<string, boolean> => {
|
||||
if (route && route.Modal) {
|
||||
@ -70,25 +66,12 @@ function SideBar ({ className, collapse, handleResize, isCollapsed, isMenuOpen,
|
||||
<NetworkModal onClose={_toggleModal('network')}/>
|
||||
)}
|
||||
<div className='apps--SideBar'>
|
||||
<div className='apps--SideBar-border ui--highlight--border' />
|
||||
<Menu
|
||||
secondary
|
||||
vertical
|
||||
>
|
||||
<div className='apps--SideBar-Scroll'>
|
||||
<div
|
||||
className='apps--SideBar-logo'
|
||||
onClick={_toggleModal('network')}
|
||||
>
|
||||
<ChainImg />
|
||||
<div className='info'>
|
||||
<Chain className='chain' />
|
||||
{runtimeVersion && (
|
||||
<div className='runtimeVersion'>{t('version {{version}}', { replace: { version: runtimeVersion.specVersion.toNumber() } })}</div>
|
||||
)}
|
||||
<BestNumber label='#' />
|
||||
</div>
|
||||
</div>
|
||||
<ChainInfo onClick={_toggleModal('network')} />
|
||||
{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;
|
||||
|
||||
23
packages/apps/src/WarmUp.tsx
Normal file
23
packages/apps/src/WarmUp.tsx
Normal file
@ -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<any>(isApiReady ? api.derive.balances?.fees : undefined, []);
|
||||
const indexes = useCall<any>(isApiReady ? api.derive.accounts?.indexes : undefined, []);
|
||||
const registrars = useCall<any>(isApiReady ? api.query.identity?.registrars : undefined, []);
|
||||
const staking = useCall<any>(isApiReady ? api.derive.staking?.overview : undefined, []);
|
||||
const [hasValues, setHasValues] = useState(false);
|
||||
|
||||
useEffect((): void => {
|
||||
setHasValues(!!fees || !!indexes || !!registrars || !!staking);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={`apps--api-warm ${hasValues}`} />
|
||||
);
|
||||
}
|
||||
@ -37,6 +37,10 @@ export default createGlobalStyle<Props>`
|
||||
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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user