Commit dfcb4027 authored by tom's avatar tom

"go back" and ref fixes

parent b60ca63e
...@@ -30,7 +30,7 @@ export default function useNavItems() { ...@@ -30,7 +30,7 @@ export default function useNavItems() {
{ text: 'Tokens', url: link('tokens'), icon: tokensIcon, isActive: currentRoute === 'tokens', isNewUi: true }, { text: 'Tokens', url: link('tokens'), icon: tokensIcon, isActive: currentRoute === 'tokens', isNewUi: true },
{ text: 'Accounts', url: link('accounts'), icon: walletIcon, isActive: currentRoute === 'accounts', isNewUi: true }, { text: 'Accounts', url: link('accounts'), icon: walletIcon, isActive: currentRoute === 'accounts', isNewUi: true },
isMarketplaceFilled ? isMarketplaceFilled ?
{ text: 'Apps', url: link('apps'), icon: appsIcon, isActive: currentRoute === 'apps', isNewUi: true } : null, { text: 'Apps', url: link('apps'), icon: appsIcon, isActive: currentRoute.startsWith('app'), isNewUi: true } : null,
{ text: 'Charts & stats', url: link('stats'), icon: statsIcon, isActive: currentRoute === 'stats', isNewUi: true }, { text: 'Charts & stats', url: link('stats'), icon: statsIcon, isActive: currentRoute === 'stats', isNewUi: true },
// there should be custom site sections like Stats, Faucet, More, etc but never an 'other' // there should be custom site sections like Stats, Faucet, More, etc but never an 'other'
// examples https://explorer-edgenet.polygon.technology/ and https://explorer.celo.org/ // examples https://explorer-edgenet.polygon.technology/ and https://explorer.celo.org/
......
...@@ -6,7 +6,6 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types'; ...@@ -6,7 +6,6 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types';
import { useAppContext } from 'lib/appContext'; import { useAppContext } from 'lib/appContext';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import useQueryWithPages from 'lib/hooks/useQueryWithPages'; import useQueryWithPages from 'lib/hooks/useQueryWithPages';
import isBrowser from 'lib/isBrowser';
import BlockDetails from 'ui/block/BlockDetails'; import BlockDetails from 'ui/block/BlockDetails';
import TextAd from 'ui/shared/ad/TextAd'; import TextAd from 'ui/shared/ad/TextAd';
import Page from 'ui/shared/Page/Page'; import Page from 'ui/shared/Page/Page';
...@@ -24,7 +23,6 @@ const TAB_LIST_PROPS = { ...@@ -24,7 +23,6 @@ const TAB_LIST_PROPS = {
const BlockPageContent = () => { const BlockPageContent = () => {
const router = useRouter(); const router = useRouter();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const isInBrowser = isBrowser();
const appProps = useAppContext(); const appProps = useAppContext();
const blockTxsQuery = useQueryWithPages({ const blockTxsQuery = useQueryWithPages({
...@@ -46,15 +44,14 @@ const BlockPageContent = () => { ...@@ -46,15 +44,14 @@ const BlockPageContent = () => {
const hasPagination = !isMobile && router.query.tab === 'txs' && blockTxsQuery.isPaginationVisible; const hasPagination = !isMobile && router.query.tab === 'txs' && blockTxsQuery.isPaginationVisible;
const referrer = isInBrowser ? window.document.referrer : appProps.referrer; const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/blocks');
const hasGoBackLink = referrer && referrer.includes('/blocks');
return ( return (
<Page> <Page>
<TextAd mb={ 6 }/> <TextAd mb={ 6 }/>
<PageTitle <PageTitle
text={ `Block #${ router.query.id }` } text={ `Block #${ router.query.id }` }
backLinkUrl={ hasGoBackLink ? referrer : undefined } backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined }
backLinkLabel="Back to blocks list" backLinkLabel="Back to blocks list"
/> />
<RoutedTabs <RoutedTabs
......
...@@ -6,7 +6,6 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types'; ...@@ -6,7 +6,6 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/appContext'; import { useAppContext } from 'lib/appContext';
import isBrowser from 'lib/isBrowser';
import networkExplorers from 'lib/networks/networkExplorers'; import networkExplorers from 'lib/networks/networkExplorers';
import TextAd from 'ui/shared/ad/TextAd'; import TextAd from 'ui/shared/ad/TextAd';
import LinkExternal from 'ui/shared/LinkExternal'; import LinkExternal from 'ui/shared/LinkExternal';
...@@ -33,11 +32,8 @@ const TABS: Array<RoutedTab> = [ ...@@ -33,11 +32,8 @@ const TABS: Array<RoutedTab> = [
const TransactionPageContent = () => { const TransactionPageContent = () => {
const router = useRouter(); const router = useRouter();
const appProps = useAppContext(); const appProps = useAppContext();
const isInBrowser = isBrowser();
const referrer = isInBrowser ? window.document.referrer : appProps.referrer; const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/txs');
const hasGoBackLink = referrer && referrer.includes('/txs');
const { data } = useApiQuery('tx', { const { data } = useApiQuery('tx', {
pathParams: { id: router.query.id?.toString() }, pathParams: { id: router.query.id?.toString() },
...@@ -74,7 +70,7 @@ const TransactionPageContent = () => { ...@@ -74,7 +70,7 @@ const TransactionPageContent = () => {
<PageTitle <PageTitle
text="Transaction details" text="Transaction details"
additionals={ additionals } additionals={ additionals }
backLinkUrl={ hasGoBackLink ? referrer : undefined } backLinkUrl={ hasGoBackLink ? appProps.referrer : undefined }
backLinkLabel="Back to transactions list" backLinkLabel="Back to transactions list"
/> />
<RoutedTabs tabs={ TABS }/> <RoutedTabs tabs={ TABS }/>
......
import type { LinkProps } from '@chakra-ui/react'; import type { LinkProps } from '@chakra-ui/react';
import { Link } from '@chakra-ui/react'; import { Link } from '@chakra-ui/react';
import NextLink from 'next/link'; import NextLink from 'next/link';
import type { LegacyRef } from 'react';
import React from 'react'; import React from 'react';
// NOTE! use this component only for links to pages that are completely implemented in new UI // NOTE! use this component only for links to pages that are completely implemented in new UI
const LinkInternal = (props: LinkProps) => { const LinkInternal = (props: LinkProps, ref: LegacyRef<HTMLAnchorElement>) => {
if (!props.href) { if (!props.href) {
return <Link { ...props }/>; return <Link { ...props } ref={ ref }/>;
} }
return ( return (
<NextLink href={ props.href } passHref target={ props.target }> <NextLink href={ props.href } passHref target={ props.target }>
<Link { ...props }/> <Link { ...props } ref={ ref }/>
</NextLink> </NextLink>
); );
}; };
export default React.memo(LinkInternal); export default React.memo(React.forwardRef(LinkInternal));
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