Commit e119c4d4 authored by tom's avatar tom

more stats fixes

parent 8e7271f0
...@@ -2,8 +2,6 @@ import _debounce from 'lodash/debounce'; ...@@ -2,8 +2,6 @@ import _debounce from 'lodash/debounce';
import type { LegacyRef } from 'react'; import type { LegacyRef } from 'react';
import React from 'react'; import React from 'react';
import useUpdateEffect from 'lib/hooks/useUpdateEffect';
export default function useClientRect<E extends Element>(): [ DOMRect | null, LegacyRef<E> | undefined ] { export default function useClientRect<E extends Element>(): [ DOMRect | null, LegacyRef<E> | undefined ] {
const [ rect, setRect ] = React.useState<DOMRect | null>(null); const [ rect, setRect ] = React.useState<DOMRect | null>(null);
const nodeRef = React.useRef<E>(); const nodeRef = React.useRef<E>();
...@@ -15,7 +13,7 @@ export default function useClientRect<E extends Element>(): [ DOMRect | null, Le ...@@ -15,7 +13,7 @@ export default function useClientRect<E extends Element>(): [ DOMRect | null, Le
nodeRef.current = node; nodeRef.current = node;
}, []); }, []);
useUpdateEffect(() => { React.useEffect(() => {
const content = window.document.querySelector('main'); const content = window.document.querySelector('main');
if (!content) { if (!content) {
return; return;
......
...@@ -25,6 +25,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => { ...@@ -25,6 +25,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => {
title="Balances" title="Balances"
items={ items } items={ items }
isLoading={ isLoading } isLoading={ isLoading }
chartHeight="250px"
/> />
); );
}; };
......
import { import {
Box, Box,
Center,
Flex, Flex,
Grid, Grid,
Icon, Icon,
...@@ -111,6 +112,49 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -111,6 +112,49 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
return <ChartWidgetSkeleton hasDescription={ Boolean(description) }/>; return <ChartWidgetSkeleton hasDescription={ Boolean(description) }/>;
} }
const hasItems = items && items.length > 2;
const content = (() => {
if (isError) {
return (
<Flex
alignItems="center"
justifyContent="center"
flexGrow={ 1 }
py={ 4 }
>
<Text
variant="secondary"
fontSize="sm"
textAlign="center"
>
{ `The data didn${ apos }t load. Please, ` }
<Link href={ window.document.location.href }>try to reload the page.</Link>
</Text>
</Flex>
);
}
if (!hasItems) {
return (
<Center flexGrow={ 1 }>
<Text variant="secondary" fontSize="sm">No data</Text>
</Center>
);
}
return (
<Box h={ chartHeight || 'auto' } maxW="100%">
<ChartWidgetGraph
items={ items }
onZoom={ handleZoom }
isZoomResetInitial={ isZoomResetInitial }
title={ title }
/>
</Box>
);
})();
return ( return (
<> <>
<Box <Box
...@@ -167,7 +211,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -167,7 +211,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
/> />
</Tooltip> </Tooltip>
{ !isError && ( { hasItems && (
<Menu> <Menu>
<MenuButton <MenuButton
gridColumn={ 3 } gridColumn={ 3 }
...@@ -216,36 +260,10 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -216,36 +260,10 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
) } ) }
</Grid> </Grid>
{ items ? ( { content }
<Box h={ chartHeight || 'auto' } maxW="100%">
<ChartWidgetGraph
margin={{ bottom: 20 }}
items={ items }
onZoom={ handleZoom }
isZoomResetInitial={ isZoomResetInitial }
title={ title }
/>
</Box>
) : (
<Flex
alignItems="center"
justifyContent="center"
flexGrow={ 1 }
py={ 4 }
>
<Text
variant="secondary"
fontSize="sm"
textAlign="center"
>
{ `The data didn${ apos }t load. Please, ` }
<Link href={ window.document.location.href }>try to reload the page.</Link>
</Text>
</Flex>
) }
</Box> </Box>
{ items && ( { hasItems && (
<FullscreenChartModal <FullscreenChartModal
isOpen={ isFullscreen } isOpen={ isFullscreen }
items={ items } items={ items }
......
...@@ -23,7 +23,7 @@ interface Props { ...@@ -23,7 +23,7 @@ interface Props {
items: Array<TimeChartItem>; items: Array<TimeChartItem>;
onZoom: () => void; onZoom: () => void;
isZoomResetInitial: boolean; isZoomResetInitial: boolean;
margin: ChartMargin; margin?: ChartMargin;
} }
const MAX_SHOW_ITEMS = 100; const MAX_SHOW_ITEMS = 100;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment