diff --git a/packages/apps/src/Content/index.tsx b/packages/apps/src/Content/index.tsx index 7f9b684271..341129f19a 100644 --- a/packages/apps/src/Content/index.tsx +++ b/packages/apps/src/Content/index.tsx @@ -2,11 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import React, { Suspense, useContext } from 'react'; +import { Route } from '@polkadot/apps-routing/types'; + +import React, { Suspense, useContext, useMemo } from 'react'; import { useLocation } from 'react-router-dom'; import styled from 'styled-components'; import routing from '@polkadot/apps-routing'; -import { ErrorBoundary, StatusContext } from '@polkadot/react-components'; +import { ErrorBoundary, Spinner, StatusContext } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; import Status from './Status'; @@ -17,11 +19,15 @@ interface Props { className?: string; } -const unknown = { +const NOT_FOUND: Route = { Component: NotFound, display: { needsApi: undefined }, + i18n: { + defaultValue: 'Unknown' + }, + icon: 'cancel', isIgnored: false, name: '' }; @@ -31,15 +37,24 @@ function Content ({ className }: Props): React.ReactElement { const { t } = useTranslation(); const { isApiConnected, isApiReady } = useApi(); const { queueAction, stqueue, txqueue } = useContext(StatusContext); - const app = location.pathname.slice(1) || ''; - const { Component, display: { needsApi }, name } = routing.routes.find((route): boolean => - !!(route && app.startsWith(route.name)) - ) || unknown; + const { Component, display: { needsApi }, name } = useMemo( + (): Route => { + const app = location.pathname.slice(1) || ''; + const found = routing.routes.find((route) => !!(route && app.startsWith(route.name))); + + return found || NOT_FOUND; + }, + [location] + ); return (
{needsApi && (!isApiReady || !isApiConnected) - ?
{t('Waiting for API to be connected and ready.')}
+ ? ( +
+ +
+ ) : ( <> @@ -80,6 +95,6 @@ export default React.memo(styled(Content)` } .connecting { - padding: 1rem 0; + padding: 3.5rem 0; } `); diff --git a/packages/react-components/src/Spinner.tsx b/packages/react-components/src/Spinner.tsx index 3b049dcdd0..6d176d6408 100644 --- a/packages/react-components/src/Spinner.tsx +++ b/packages/react-components/src/Spinner.tsx @@ -2,29 +2,44 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import React from 'react'; +import React, { useMemo } from 'react'; import styled from 'styled-components'; import { useTranslation } from './translate'; interface Props { className?: string; + label?: React.ReactNode; variant?: 'app' | 'push' | 'mini'; } -function Spinner ({ className, variant = 'app' }: Props): React.ReactElement | null { +function Spinner ({ className, label, variant = 'app' }: Props): React.ReactElement | null { const { t } = useTranslation(); - const strokeWidth = variant === 'app' ? 2 : 4; + const strokeWidth = useMemo( + () => variant === 'app' ? 2 : 4, + [variant] + ); return (
- - + +
{variant === 'app' && ( -
{t('Retrieving data')}
+
{label || t('Retrieving data')}
)}
);