Commit ad970afd authored by tom's avatar tom

refactor back link for page title

parent d6e382ce
...@@ -38,8 +38,6 @@ const AddressPageContent = () => { ...@@ -38,8 +38,6 @@ const AddressPageContent = () => {
const appProps = useAppContext(); const appProps = useAppContext();
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/accounts');
const tabsScrollRef = React.useRef<HTMLDivElement>(null); const tabsScrollRef = React.useRef<HTMLDivElement>(null);
const hash = getQueryParamString(router.query.hash); const hash = getQueryParamString(router.query.hash);
...@@ -98,6 +96,19 @@ const AddressPageContent = () => { ...@@ -98,6 +96,19 @@ const AddressPageContent = () => {
const content = addressQuery.isError ? null : <RoutedTabs tabs={ tabs } tabListProps={{ mt: 8 }}/>; const content = addressQuery.isError ? null : <RoutedTabs tabs={ tabs } tabListProps={{ mt: 8 }}/>;
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/accounts');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to top accounts list',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
{ addressQuery.isLoading ? <Skeleton h={{ base: 12, lg: 6 }} mb={ 6 } w="100%" maxW="680px"/> : <TextAd mb={ 6 }/> } { addressQuery.isLoading ? <Skeleton h={{ base: 12, lg: 6 }} mb={ 6 } w="100%" maxW="680px"/> : <TextAd mb={ 6 }/> }
...@@ -107,8 +118,7 @@ const AddressPageContent = () => { ...@@ -107,8 +118,7 @@ const AddressPageContent = () => {
<PageTitle <PageTitle
text={ `${ addressQuery.data?.is_contract ? 'Contract' : 'Address' } details` } text={ `${ addressQuery.data?.is_contract ? 'Contract' : 'Address' } details` }
additionalsRight={ tagsNode } additionalsRight={ tagsNode }
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to top accounts list"
/> />
) } ) }
<AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/> <AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/>
......
...@@ -54,7 +54,18 @@ const BlockPageContent = () => { ...@@ -54,7 +54,18 @@ const BlockPageContent = () => {
const hasPagination = !isMobile && tab === 'txs' && blockTxsQuery.isPaginationVisible; const hasPagination = !isMobile && tab === 'txs' && blockTxsQuery.isPaginationVisible;
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/blocks'); const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/blocks');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to blocks list',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
...@@ -64,8 +75,7 @@ const BlockPageContent = () => { ...@@ -64,8 +75,7 @@ const BlockPageContent = () => {
) : ( ) : (
<PageTitle <PageTitle
text={ `Block #${ blockQuery.data?.height }` } text={ `Block #${ blockQuery.data?.height }` }
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to blocks list"
/> />
) } ) }
<RoutedTabs <RoutedTabs
......
...@@ -20,7 +20,6 @@ import PageTitle from 'ui/shared/Page/PageTitle'; ...@@ -20,7 +20,6 @@ import PageTitle from 'ui/shared/Page/PageTitle';
const ContractVerification = () => { const ContractVerification = () => {
const appProps = useAppContext(); const appProps = useAppContext();
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
const router = useRouter(); const router = useRouter();
const hash = getQueryParamString(router.query.hash); const hash = getQueryParamString(router.query.hash);
...@@ -83,12 +82,24 @@ const ContractVerification = () => { ...@@ -83,12 +82,24 @@ const ContractVerification = () => {
); );
})(); })();
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to contract',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
<PageTitle <PageTitle
text="New smart contract verification" text="New smart contract verification"
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to contract"
/> />
{ hash && ( { hash && (
<Address mb={ 12 }> <Address mb={ 12 }>
......
...@@ -50,7 +50,6 @@ const CsvExport = () => { ...@@ -50,7 +50,6 @@ const CsvExport = () => {
const addressHash = router.query.address?.toString() || ''; const addressHash = router.query.address?.toString() || '';
const exportType = router.query.type?.toString() || ''; const exportType = router.query.type?.toString() || '';
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
const addressQuery = useApiQuery('address', { const addressQuery = useApiQuery('address', {
pathParams: { hash: addressHash }, pathParams: { hash: addressHash },
...@@ -59,6 +58,19 @@ const CsvExport = () => { ...@@ -59,6 +58,19 @@ const CsvExport = () => {
}, },
}); });
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to address',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
if (!isCorrectExportType(exportType) || !addressHash || addressQuery.error?.status === 400) { if (!isCorrectExportType(exportType) || !addressHash || addressQuery.error?.status === 400) {
throw Error('Not found', { cause: { status: 404 } }); throw Error('Not found', { cause: { status: 404 } });
} }
...@@ -79,8 +91,7 @@ const CsvExport = () => { ...@@ -79,8 +91,7 @@ const CsvExport = () => {
<Page> <Page>
<PageTitle <PageTitle
text="Export data to CSV file" text="Export data to CSV file"
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to address"
/> />
<Flex mb={ 10 } whiteSpace="pre-wrap" flexWrap="wrap"> <Flex mb={ 10 } whiteSpace="pre-wrap" flexWrap="wrap">
<span>Export { EXPORT_TYPES[exportType].text } for address </span> <span>Export { EXPORT_TYPES[exportType].text } for address </span>
......
...@@ -17,14 +17,25 @@ const Sol2Uml = () => { ...@@ -17,14 +17,25 @@ const Sol2Uml = () => {
const appProps = useAppContext(); const appProps = useAppContext();
const addressHash = router.query.address?.toString() || ''; const addressHash = router.query.address?.toString() || '';
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to address',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
<PageTitle <PageTitle
text="Solidity UML diagram" text="Solidity UML diagram"
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to address"
/> />
<Flex mb={ 10 }> <Flex mb={ 10 }>
<span>For contract</span> <span>For contract</span>
......
...@@ -34,8 +34,6 @@ const TokenPageContent = () => { ...@@ -34,8 +34,6 @@ const TokenPageContent = () => {
const appProps = useAppContext(); const appProps = useAppContext();
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/tokens');
const scrollRef = React.useRef<HTMLDivElement>(null); const scrollRef = React.useRef<HTMLDivElement>(null);
const hashString = router.query.hash?.toString(); const hashString = router.query.hash?.toString();
...@@ -152,6 +150,19 @@ const TokenPageContent = () => { ...@@ -152,6 +150,19 @@ const TokenPageContent = () => {
}; };
}, [ isMobile ]); }, [ isMobile ]);
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/tokens');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to tokens list',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
{ tokenQuery.isLoading ? ( { tokenQuery.isLoading ? (
...@@ -167,8 +178,7 @@ const TokenPageContent = () => { ...@@ -167,8 +178,7 @@ const TokenPageContent = () => {
<TextAd mb={ 6 }/> <TextAd mb={ 6 }/>
<PageTitle <PageTitle
text={ `${ tokenQuery.data?.name || 'Unnamed' }${ tokenSymbolText } token` } text={ `${ tokenQuery.data?.name || 'Unnamed' }${ tokenSymbolText } token` }
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to tokens list"
additionalsLeft={ ( additionalsLeft={ (
<TokenLogo hash={ tokenQuery.data?.address } name={ tokenQuery.data?.name } boxSize={ 6 }/> <TokenLogo hash={ tokenQuery.data?.address } name={ tokenQuery.data?.name } boxSize={ 6 }/>
) } ) }
......
...@@ -33,7 +33,6 @@ const TransactionPageContent = () => { ...@@ -33,7 +33,6 @@ const TransactionPageContent = () => {
const router = useRouter(); const router = useRouter();
const appProps = useAppContext(); const appProps = useAppContext();
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/txs');
const hash = getQueryParamString(router.query.hash); const hash = getQueryParamString(router.query.hash);
const { data } = useApiQuery('tx', { const { data } = useApiQuery('tx', {
...@@ -65,14 +64,26 @@ const TransactionPageContent = () => { ...@@ -65,14 +64,26 @@ const TransactionPageContent = () => {
</Flex> </Flex>
); );
const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/txs');
if (!hasGoBackLink) {
return;
}
return {
label: 'Back to transactions list',
url: appProps.referrer,
};
}, [ appProps.referrer ]);
return ( return (
<Page> <Page>
<TextAd mb={ 6 }/> <TextAd mb={ 6 }/>
<PageTitle <PageTitle
text="Transaction details" text="Transaction details"
additionalsRight={ additionals } additionalsRight={ additionals }
backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined } backLink={ backLink }
backLinkLabel="Back to transactions list"
/> />
<RoutedTabs tabs={ TABS }/> <RoutedTabs tabs={ TABS }/>
</Page> </Page>
......
...@@ -43,8 +43,7 @@ test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount }) ...@@ -43,8 +43,7 @@ test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount })
<PageTitle <PageTitle
text="Title" text="Title"
withTextAd withTextAd
backLinkLabel="Back" backLink={{ label: 'Back', url: 'back' }}
backLinkUrl="back"
// additionalsLeft={ left } // additionalsLeft={ left }
additionalsRight="Privet" additionalsRight="Privet"
/> />
...@@ -60,8 +59,7 @@ test('long title with text ad, back link and addons +@mobile', async({ mount }) ...@@ -60,8 +59,7 @@ test('long title with text ad, back link and addons +@mobile', async({ mount })
<PageTitle <PageTitle
text="This title is long, really long" text="This title is long, really long"
withTextAd withTextAd
backLinkLabel="Back" backLink={{ label: 'Back', url: 'back' }}
backLinkUrl="back"
additionalsRight="Privet, kak dela?" additionalsRight="Privet, kak dela?"
/> />
</TestApp>, </TestApp>,
......
import { Heading, Flex, Grid, Tooltip, Icon, chakra } from '@chakra-ui/react'; import { Heading, Flex, Grid, Tooltip, Icon, Link, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import eastArrowIcon from 'icons/arrows/east.svg'; import eastArrowIcon from 'icons/arrows/east.svg';
import TextAd from 'ui/shared/ad/TextAd'; import TextAd from 'ui/shared/ad/TextAd';
import LinkInternal from 'ui/shared/LinkInternal'; import LinkInternal from 'ui/shared/LinkInternal';
type BackLinkProp = { label: string; url: string } | { label: string; onClick: () => void };
type Props = { type Props = {
text: string; text: string;
additionalsLeft?: React.ReactNode; additionalsLeft?: React.ReactNode;
additionalsRight?: React.ReactNode; additionalsRight?: React.ReactNode;
withTextAd?: boolean; withTextAd?: boolean;
className?: string; className?: string;
backLinkLabel?: string; backLink?: BackLinkProp;
backLinkUrl?: string;
} }
const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLinkUrl, backLinkLabel, className }: Props) => { const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLink, className }: Props) => {
const title = ( const title = (
<Heading <Heading
as="h1" as="h1"
...@@ -27,6 +28,32 @@ const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLi ...@@ -27,6 +28,32 @@ const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLi
</Heading> </Heading>
); );
const backLinkComponent = (() => {
if (!backLink) {
return null;
}
const icon = <Icon as={ eastArrowIcon } boxSize={ 6 } transform="rotate(180deg)" margin="auto"/>;
if ('url' in backLink) {
return (
<Tooltip label={ backLink.label }>
<LinkInternal display="inline-flex" href={ backLink.url } h="40px">
{ icon }
</LinkInternal>
</Tooltip>
);
}
return (
<Tooltip label={ backLink.label }>
<Link display="inline-flex" onClick={ backLink.onClick } h="40px">
{ icon }
</Link>
</Tooltip>
);
})();
return ( return (
<Flex <Flex
columnGap={ 3 } columnGap={ 3 }
...@@ -39,16 +66,10 @@ const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLi ...@@ -39,16 +66,10 @@ const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLi
> >
<Flex flexWrap="wrap" columnGap={ 3 } alignItems="center" width={ withTextAd ? 'unset' : '100%' } flexShrink={ 0 }> <Flex flexWrap="wrap" columnGap={ 3 } alignItems="center" width={ withTextAd ? 'unset' : '100%' } flexShrink={ 0 }>
<Grid <Grid
templateColumns={ [ backLinkUrl && 'auto', additionalsLeft && 'auto', '1fr' ].filter(Boolean).join(' ') } templateColumns={ [ backLinkComponent && 'auto', additionalsLeft && 'auto', '1fr' ].filter(Boolean).join(' ') }
columnGap={ 3 } columnGap={ 3 }
> >
{ backLinkUrl && ( { backLinkComponent }
<Tooltip label={ backLinkLabel }>
<LinkInternal display="inline-flex" href={ backLinkUrl } h="40px">
<Icon as={ eastArrowIcon } boxSize={ 6 } transform="rotate(180deg)" margin="auto"/>
</LinkInternal>
</Tooltip>
) }
{ additionalsLeft !== undefined && ( { additionalsLeft !== undefined && (
<Flex h="40px" alignItems="center"> <Flex h="40px" alignItems="center">
{ additionalsLeft } { additionalsLeft }
......
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