Commit 1df3a163 authored by isstuev's avatar isstuev

change mobile page titke for the chart

parent 3df4bd4f
import React from 'react'; import React from 'react';
import * as balanceHistoryMock from 'mocks/address/coinBalanceHistory'; import * as balanceHistoryMock from 'mocks/address/coinBalanceHistory';
import { test, expect } from 'playwright/lib'; import { test, expect, devices } from 'playwright/lib';
import AddressCoinBalance from './AddressCoinBalance'; import AddressCoinBalance from './AddressCoinBalance';
...@@ -12,7 +12,7 @@ const hooksConfig = { ...@@ -12,7 +12,7 @@ const hooksConfig = {
}, },
}; };
test('base view +@dark-mode +@mobile', async({ render, page, mockApiResponse }) => { test('base view +@dark-mode', async({ render, page, mockApiResponse }) => {
await mockApiResponse('address_coin_balance', balanceHistoryMock.baseResponse, { pathParams: { hash: addressHash } }); await mockApiResponse('address_coin_balance', balanceHistoryMock.baseResponse, { pathParams: { hash: addressHash } });
await mockApiResponse('address_coin_balance_chart', balanceHistoryMock.chartResponse, { pathParams: { hash: addressHash } }); await mockApiResponse('address_coin_balance_chart', balanceHistoryMock.chartResponse, { pathParams: { hash: addressHash } });
const component = await render(<AddressCoinBalance/>, { hooksConfig }); const component = await render(<AddressCoinBalance/>, { hooksConfig });
...@@ -23,3 +23,19 @@ test('base view +@dark-mode +@mobile', async({ render, page, mockApiResponse }) ...@@ -23,3 +23,19 @@ test('base view +@dark-mode +@mobile', async({ render, page, mockApiResponse })
await page.mouse.move(240, 100); await page.mouse.move(240, 100);
await expect(component).toHaveScreenshot(); await expect(component).toHaveScreenshot();
}); });
test.describe('mobile', () => {
test.use({ viewport: devices['iPhone 13 Pro'].viewport });
test('base view', async({ render, page, mockApiResponse }) => {
await mockApiResponse('address_coin_balance', balanceHistoryMock.baseResponse, { pathParams: { hash: addressHash } });
await mockApiResponse('address_coin_balance_chart', balanceHistoryMock.chartResponse, { pathParams: { hash: addressHash } });
const component = await render(<AddressCoinBalance/>, { hooksConfig });
await page.waitForFunction(() => {
return document.querySelector('path[data-name="chart-Balances-small"]')?.getAttribute('opacity') === '1';
});
await page.mouse.move(100, 100);
await page.mouse.move(240, 100);
await expect(component).toHaveScreenshot();
});
});
import { Button, Flex, IconButton, Link, Text } from '@chakra-ui/react'; import { Button, Flex, Link, Text } from '@chakra-ui/react';
import type { NextRouter } from 'next/router'; import type { NextRouter } from 'next/router';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
...@@ -95,10 +95,14 @@ const Chart = () => { ...@@ -95,10 +95,14 @@ const Chart = () => {
const onIntervalChange = React.useCallback((interval: StatsIntervalIds) => { const onIntervalChange = React.useCallback((interval: StatsIntervalIds) => {
setIntervalState(interval); setIntervalState(interval);
router.push({ router.push(
pathname: router.pathname, {
query: { ...router.query, interval }, pathname: router.pathname,
}); query: { ...router.query, interval },
},
undefined,
{ shallow: true },
);
}, [ setIntervalState, router ]); }, [ setIntervalState, router ]);
const onResolutionChange = React.useCallback((resolution: Resolution) => { const onResolutionChange = React.useCallback((resolution: Resolution) => {
...@@ -143,16 +147,7 @@ const Chart = () => { ...@@ -143,16 +147,7 @@ const Chart = () => {
const isInfoLoading = !info && lineQuery.isPlaceholderData; const isInfoLoading = !info && lineQuery.isPlaceholderData;
const shareButton = isMobile ? ( const shareButton = (
<IconButton
aria-label="share"
variant="outline"
boxSize={ 8 }
size="sm"
icon={ <IconSvg name="share" boxSize={ 5 }/> }
onClick={ onShare }
/>
) : (
<Button <Button
leftIcon={ <IconSvg name="share" w={ 4 } h={ 4 }/> } leftIcon={ <IconSvg name="share" w={ 4 } h={ 4 }/> }
colorScheme="blue" colorScheme="blue"
...@@ -169,41 +164,6 @@ const Chart = () => { ...@@ -169,41 +164,6 @@ const Chart = () => {
</Button> </Button>
); );
const shareAndMenu = (
<Flex alignItems="center" ml="auto" gap={ 3 }>
{ /* TS thinks window.navigator.share can't be undefined, but it can */ }
{ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ }
{ (isInBrowser && ((window.navigator.share as any) ?
shareButton :
(
<CopyToClipboard
text={ config.app.baseUrl + router.asPath }
size={ 5 }
type="link"
variant="outline"
colorScheme="blue"
display="flex"
borderRadius="8px"
width={ 8 }
height={ 8 }
/>
)
)) }
{ (hasItems || lineQuery.isPlaceholderData) && (
<ChartMenu
items={ items }
title={ info?.title || '' }
isLoading={ lineQuery.isPlaceholderData }
chartRef={ ref }
resolution={ resolution }
zoomRange={ zoomRange }
handleZoom={ handleZoom }
handleZoomReset={ handleZoomReset }
/>
) }
</Flex>
);
return ( return (
<> <>
<PageTitle <PageTitle
...@@ -211,14 +171,13 @@ const Chart = () => { ...@@ -211,14 +171,13 @@ const Chart = () => {
mb={ 3 } mb={ 3 }
isLoading={ isInfoLoading } isLoading={ isInfoLoading }
backLink={ backLink } backLink={ backLink }
afterTitle={ isMobile ? shareAndMenu : undefined }
secondRow={ info?.description || lineQuery.data?.info?.description } secondRow={ info?.description || lineQuery.data?.info?.description }
withTextAd withTextAd
/> />
<Flex alignItems="center" justifyContent="space-between"> <Flex alignItems="center" justifyContent="space-between">
<Flex alignItems="center" gap={{ base: 3, lg: 6 }} maxW="100%" overflow="hidden"> <Flex alignItems="center" gap={{ base: 3, lg: 6 }} maxW="100%" overflow="hidden">
<Flex alignItems="center" gap={ 3 }> <Flex alignItems="center" gap={ 3 }>
<Text>Period</Text> { !isMobile && <Text>Period</Text> }
<ChartIntervalSelect interval={ interval } onIntervalChange={ onIntervalChange }/> <ChartIntervalSelect interval={ interval } onIntervalChange={ onIntervalChange }/>
</Flex> </Flex>
{ lineQuery.data?.info?.resolutions && lineQuery.data?.info?.resolutions.length > 1 && ( { lineQuery.data?.info?.resolutions && lineQuery.data?.info?.resolutions.length > 1 && (
...@@ -243,7 +202,39 @@ const Chart = () => { ...@@ -243,7 +202,39 @@ const Chart = () => {
</Link> </Link>
) } ) }
</Flex> </Flex>
{ !isMobile && shareAndMenu } <Flex alignItems="center" gap={ 3 }>
{ /* TS thinks window.navigator.share can't be undefined, but it can */ }
{ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ }
{ !isMobile && (isInBrowser && ((window.navigator.share as any) ?
shareButton :
(
<CopyToClipboard
text={ config.app.baseUrl + router.asPath }
size={ 5 }
type="link"
variant="outline"
colorScheme="blue"
display="flex"
borderRadius="8px"
width={ 8 }
height={ 8 }
/>
)
)) }
{ (hasItems || lineQuery.isPlaceholderData) && (
<ChartMenu
items={ items }
title={ info?.title || '' }
isLoading={ lineQuery.isPlaceholderData }
chartRef={ ref }
resolution={ resolution }
zoomRange={ zoomRange }
handleZoom={ handleZoom }
handleZoomReset={ handleZoomReset }
chartUrl={ isMobile ? window.location.href : undefined }
/>
) }
</Flex>
</Flex> </Flex>
<Flex <Flex
ref={ ref } ref={ ref }
......
...@@ -14,10 +14,6 @@ import React from 'react'; ...@@ -14,10 +14,6 @@ import React from 'react';
import type { TimeChartItem } from './types'; import type { TimeChartItem } from './types';
import type { Resolution } from '@blockscout/stats-types'; import type { Resolution } from '@blockscout/stats-types';
import type { Route } from 'nextjs-routes';
import { route } from 'nextjs-routes';
import config from 'configs/app';
import dayjs from 'lib/date/dayjs'; import dayjs from 'lib/date/dayjs';
import isBrowser from 'lib/isBrowser'; import isBrowser from 'lib/isBrowser';
import saveAsCSV from 'lib/saveAsCSV'; import saveAsCSV from 'lib/saveAsCSV';
...@@ -33,7 +29,7 @@ export type Props = { ...@@ -33,7 +29,7 @@ export type Props = {
units?: string; units?: string;
isLoading: boolean; isLoading: boolean;
chartRef: React.RefObject<HTMLDivElement>; chartRef: React.RefObject<HTMLDivElement>;
href?: Route; chartUrl?: string;
resolution?: Resolution; resolution?: Resolution;
zoomRange?: [ Date, Date ]; zoomRange?: [ Date, Date ];
handleZoom: (range: [ Date, Date ]) => void; handleZoom: (range: [ Date, Date ]) => void;
...@@ -49,7 +45,7 @@ const ChartMenu = ({ ...@@ -49,7 +45,7 @@ const ChartMenu = ({
units, units,
isLoading, isLoading,
chartRef, chartRef,
href, chartUrl,
resolution, resolution,
zoomRange, zoomRange,
handleZoom, handleZoom,
...@@ -58,7 +54,6 @@ const ChartMenu = ({ ...@@ -58,7 +54,6 @@ const ChartMenu = ({
const pngBackgroundColor = useColorModeValue('white', 'black'); const pngBackgroundColor = useColorModeValue('white', 'black');
const [ isFullscreen, setIsFullscreen ] = React.useState(false); const [ isFullscreen, setIsFullscreen ] = React.useState(false);
const chartUrl = href ? config.app.baseUrl + route(href) : '';
const { onCopy } = useClipboard(chartUrl); const { onCopy } = useClipboard(chartUrl);
const isInBrowser = isBrowser(); const isInBrowser = isBrowser();
...@@ -144,7 +139,7 @@ const ChartMenu = ({ ...@@ -144,7 +139,7 @@ const ChartMenu = ({
</MenuButton> </MenuButton>
</Skeleton> </Skeleton>
<MenuList> <MenuList>
{ href && ( { chartUrl && (
<MenuItem <MenuItem
display="flex" display="flex"
alignItems="center" alignItems="center"
......
...@@ -11,8 +11,9 @@ import React, { useRef } from 'react'; ...@@ -11,8 +11,9 @@ import React, { useRef } from 'react';
import type { TimeChartItem } from './types'; import type { TimeChartItem } from './types';
import type { Route } from 'nextjs-routes'; import { route, type Route } from 'nextjs-routes';
import config from 'configs/app';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
import ChartMenu from './ChartMenu'; import ChartMenu from './ChartMenu';
...@@ -133,7 +134,7 @@ const ChartWidget = ({ ...@@ -133,7 +134,7 @@ const ChartWidget = ({
items={ items } items={ items }
title={ title } title={ title }
description={ description } description={ description }
href={ href } chartUrl={ href ? config.app.baseUrl + route(href) : undefined }
isLoading={ isLoading } isLoading={ isLoading }
chartRef={ ref } chartRef={ ref }
units={ units } units={ units }
......
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