diff --git a/packages/apps/src/Apps.tsx b/packages/apps/src/Apps.tsx index b29bd4bfbc..1990b2f730 100644 --- a/packages/apps/src/Apps.tsx +++ b/packages/apps/src/Apps.tsx @@ -8,16 +8,17 @@ import { SideBarTransition, SIDEBAR_TRANSITION_DURATION, SIDEBAR_MENU_THRESHOLD import React from 'react'; import { hot } from 'react-hot-loader/root'; import store from 'store'; -import styled, { ThemeProvider } from 'styled-components'; -import { media } from '@polkadot/ui-app'; -import { classes } from '@polkadot/ui-app/util'; +import { ThemeProvider } from 'styled-components'; import Signer from '@polkadot/ui-signer'; import settings from '@polkadot/ui-settings'; -import Connecting from './Connecting'; +import ConnectingOverlay from './overlays/Connecting'; +import AccountsOverlay from './overlays/Accounts'; import Content from './Content'; import SideBar from './SideBar'; +import { Wrapper } from './styles'; + type Props = BareProps & {}; type State = { @@ -27,22 +28,6 @@ type State = { transition: SideBarTransition }; -const Wrapper = styled.div` - align-items: stretch; - box-sizing: border-box; - display: flex; - min-height: 100vh; - - header { - margin-bottom: 1.4rem; - text-align: center; - - ${media.TABLET` - margin-bottom: 2rem; - `} - } -`; - class Apps extends React.Component { state: State; @@ -71,19 +56,11 @@ class Apps extends React.Component { } render () { - const { isCollapsed, isMenu, menuOpen } = this.state; + return ( - + {this.renderMenuBg()} { - + + ); @@ -158,11 +136,7 @@ class Apps extends React.Component { private renderMenuBg = () => { return (
diff --git a/packages/apps/src/SideBar/Item.tsx b/packages/apps/src/SideBar/Item.tsx index 415aa4b803..76f464e32d 100644 --- a/packages/apps/src/SideBar/Item.tsx +++ b/packages/apps/src/SideBar/Item.tsx @@ -36,7 +36,6 @@ class Item extends React.PureComponent { } render () { - const { route: { i18n, icon, name }, t, isCollapsed } = this.props; if (!this.isVisible()) { diff --git a/packages/apps/src/TopBar.tsx b/packages/apps/src/TopBar.tsx index bb02759056..1f451dc253 100644 --- a/packages/apps/src/TopBar.tsx +++ b/packages/apps/src/TopBar.tsx @@ -5,40 +5,13 @@ // Unused atm, experiment as a replacement for NodeInfo on the SideBar import React from 'react'; -import styled from 'styled-components'; import { BestNumber, Chain, NodeName, NodeVersion } from '@polkadot/ui-reactive'; +import { TopBar as Wrapper } from './styles'; + type Props = {}; -const Wrapper = styled.div` - background: #f2f2f2; - font-size: 0.85rem; - line-height: 1rem; - overflow: hidden; - padding: 0.5rem 1rem; - position: fixed; - right: 0; - text-align: right; - text-overflow: ellipsis; - white-space: nowrap; - top: 0; - - div { - display: inline-block; - vertical-align: middle; - } - - > div { - border-left: 1px solid #ccc; - padding: 0 0.5rem; - - &:first-child { - border-width: 0; - } - } -`; - export default class TopBar extends React.PureComponent { render () { return ( diff --git a/packages/apps/src/overlays/Accounts.tsx b/packages/apps/src/overlays/Accounts.tsx new file mode 100644 index 0000000000..8828d428b2 --- /dev/null +++ b/packages/apps/src/overlays/Accounts.tsx @@ -0,0 +1,91 @@ +// Copyright 2017-2019 @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 { I18nProps } from '@polkadot/ui-app/types'; +import { ApiProps } from '@polkadot/ui-api/types'; +import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; + +import React from 'react'; +import { Trans } from 'react-i18next'; +import { Link } from 'react-router-dom'; +import { withApi, withMulti, withObservable } from '@polkadot/ui-api'; +import { Icon } from '@polkadot/ui-app'; +import accountObservable from '@polkadot/ui-keyring/observable/accounts'; + +import { Accounts as Wrapper, OverlayClose } from '../styles'; + +import translate from '../translate'; + +type Props = I18nProps & ApiProps & { + allAccounts?: SubjectInfo +}; + +type State = { + isDismissed: boolean, + hasAccounts: boolean +}; + +class Accounts extends React.PureComponent { + state: State = { + isDismissed: false, + hasAccounts: false + }; + + static getDerivedStateFromProps ({ allAccounts }: Props, prevState: State): State | null { + if (!allAccounts) { + return null; + } + + const hasAccounts = Object.keys(allAccounts).length !== 0; + + if (hasAccounts === prevState.hasAccounts) { + return null; + } + + return { + hasAccounts + } as State; + } + + render () { + const { isApiReady } = this.props; + const { isDismissed, hasAccounts } = this.state; + + if (!isApiReady || isDismissed || hasAccounts) { + return null; + } + + return ( + + + You have no accounts. Some features are currently hidden and will only become available once you have accounts. + {' '} + + Create an account now. + + + + + + + ); + } + + private dismiss = () => { + this.setState({ isDismissed: true }); + } +} + +export default withMulti( + Accounts, + translate, + withApi, + withObservable(accountObservable.subject, { propName: 'allAccounts' }) +); diff --git a/packages/apps/src/Connecting.tsx b/packages/apps/src/overlays/Connecting.tsx similarity index 86% rename from packages/apps/src/Connecting.tsx rename to packages/apps/src/overlays/Connecting.tsx index 06f5b1f667..0a98fd12ee 100644 --- a/packages/apps/src/Connecting.tsx +++ b/packages/apps/src/overlays/Connecting.tsx @@ -6,27 +6,14 @@ import { I18nProps } from '@polkadot/ui-app/types'; import { ApiProps } from '@polkadot/ui-api/types'; import React from 'react'; -import styled from 'styled-components'; import { withApi, withMulti } from '@polkadot/ui-api'; import settings from '@polkadot/ui-settings'; -import translate from './translate'; +import { Connecting as Wrapper } from '../styles'; + +import translate from '../translate'; type Props = I18nProps & ApiProps; - -const Wrapper = styled.div` - background: red; - color: white; - bottom: 0; - left: 0; - line-height: 1.5em; - opacity: 0.9; - padding: 1em 5em; - position: fixed; - right: 0; - text-align: center; -`; - // @ts-ignore const isFirefox = typeof InstallTrigger !== 'undefined'; diff --git a/packages/apps/src/styles.ts b/packages/apps/src/styles.ts new file mode 100644 index 0000000000..720d7c1e19 --- /dev/null +++ b/packages/apps/src/styles.ts @@ -0,0 +1,78 @@ +// Copyright 2017-2019 @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 styled from 'styled-components'; +import { media } from '@polkadot/ui-app'; + +export const Wrapper = styled.div` + align-items: stretch; + box-sizing: border-box; + display: flex; + min-height: 100vh; + + header { + margin-bottom: 1.4rem; + text-align: center; + + ${media.TABLET` + margin-bottom: 2rem; + `} + } +`; + +export const TopBar = styled.div` + background: #f2f2f2; + font-size: 0.85rem; + line-height: 1rem; + overflow: hidden; + padding: 0.5rem 1rem; + position: fixed; + right: 0; + text-align: right; + text-overflow: ellipsis; + white-space: nowrap; + top: 0; + + div { + display: inline-block; + vertical-align: middle; + } + + > div { + border-left: 1px solid #ccc; + padding: 0 0.5rem; + + &:first-child { + border-width: 0; + } + } +`; + +export const Overlay = styled.div` + bottom: 0; + left: 0; + line-height: 1.5em; + padding: 1em 5em; + position: fixed; + right: 0; + text-align: center; + z-index: 500; +`; + +export const OverlayClose = styled.div` + cursor: pointer; + position: absolute; + right: 1em; + top: 1em; +`; + +export const Connecting = styled(Overlay)` + background: red; + color: white; + opacity: 0.9; +`; + +export const Accounts = styled(Overlay)` + background: #FFFACD; +`;