Skip to content

Commit

Permalink
feat: dynamically import pages
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Jan 9, 2024
1 parent b317c8a commit ec54847
Show file tree
Hide file tree
Showing 37 changed files with 772 additions and 585 deletions.
37 changes: 37 additions & 0 deletions src/app/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client';

import dynamic from 'next/dynamic';
import * as React from 'react';

Check warning on line 4 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

import { DEFAULT_BLOCKS_LIST_LIMIT, DEFAULT_LIST_LIMIT_SMALL } from '../common/constants/constants';
import { useGlobalContext } from '../common/context/useAppContext';
import { TxListTabs } from '../features/txs-list/tabs/TxListTabs';

Check warning on line 8 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L6-L8

Added lines #L6 - L8 were not covered by tests
import { Flex } from '../ui/Flex';
import { Grid } from '../ui/Grid';

Check warning on line 10 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L10

Added line #L10 was not covered by tests
import { useColorMode } from '../ui/hooks/useColorMode';
import { SkeletonBlockList } from './_components/BlockList/SkeletonBlockList';
import { PageTitle } from './_components/PageTitle';
import { Stats } from './_components/Stats/Stats';

Check warning on line 14 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L12-L14

Added lines #L12 - L14 were not covered by tests

const BlocksList = dynamic(() => import('./_components/BlockList').then(mod => mod.BlocksList), {
loading: () => <SkeletonBlockList />,

Check warning on line 17 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L16-L17

Added lines #L16 - L17 were not covered by tests
ssr: false,
});

export default function Home() {
const { activeNetwork } = useGlobalContext();

Check warning on line 22 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L21-L22

Added lines #L21 - L22 were not covered by tests
return (
<>
<PageTitle data-test="homepage-title">Stacks Explorer</PageTitle>
{!activeNetwork.isSubnet && <Stats />}
<Grid
gap="7"
width="full"
gridTemplateColumns={['100%', '100%', 'minmax(0, 0.6fr) minmax(0, 0.4fr)']}
>
<TxListTabs limit={DEFAULT_LIST_LIMIT_SMALL} />
<BlocksList limit={DEFAULT_BLOCKS_LIST_LIMIT} />
</Grid>
</>
);
}
46 changes: 46 additions & 0 deletions src/app/address/[principal]/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use client';

import * as React from 'react';

Check warning on line 3 in src/app/address/[principal]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/PageClient.tsx#L3

Added line #L3 was not covered by tests

import { UnlockingScheduleModal } from '../../../common/components/modals/unlocking-schedule';
import { useSuspenseAccountBalance } from '../../../common/queries/useAccountBalance';
import { useAddressNonces } from '../../../common/queries/useAddressNonces';
import { hasTokenBalance } from '../../../common/utils/accounts';
import { AddressTxListTabs } from '../../../features/txs-list/tabs/AddressTxListTabs';
import { Stack } from '../../../ui/components';
import { PageTitle } from '../../_components/PageTitle';
import { AddressSummary } from './AddressSummary';
import { StxBalance } from './StxBalance';
import { TokenBalanceCard } from './TokenBalanceCard';
import { Wrapper } from './Wrapper';

Check warning on line 15 in src/app/address/[principal]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/PageClient.tsx#L5-L15

Added lines #L5 - L15 were not covered by tests

export default function AddressPage({ params: { principal } }: any) {
const { data: balance } = useSuspenseAccountBalance(principal, { refetchOnWindowFocus: true });
const { data: nonces } = useAddressNonces({ address: principal });

Check warning on line 19 in src/app/address/[principal]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/PageClient.tsx#L17-L19

Added lines #L17 - L19 were not covered by tests

const hasTokenBalances = hasTokenBalance(balance);

Check warning on line 21 in src/app/address/[principal]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/PageClient.tsx#L21

Added line #L21 was not covered by tests

return (
<>
<PageTitle>Address details</PageTitle>
<Wrapper>
<Stack gap={8}>
<AddressSummary
principal={principal}
hasTokenBalances={hasTokenBalances}
balances={balance}
lastExecutedTxNonce={nonces?.last_executed_tx_nonce}
/>
<AddressTxListTabs address={principal} />
</Stack>
{balance && (
<Stack gap={8}>
<StxBalance address={principal} />
<TokenBalanceCard address={principal} />
</Stack>
)}
</Wrapper>
<UnlockingScheduleModal balance={balance} />
</>
);
}
48 changes: 7 additions & 41 deletions src/app/address/[principal]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
'use client';

import dynamic from 'next/dynamic';

Check warning on line 3 in src/app/address/[principal]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/page.tsx#L3

Added line #L3 was not covered by tests
import * as React from 'react';

import { UnlockingScheduleModal } from '../../../common/components/modals/unlocking-schedule';
import { useSuspenseAccountBalance } from '../../../common/queries/useAccountBalance';
import { useAddressNonces } from '../../../common/queries/useAddressNonces';
import { hasTokenBalance } from '../../../common/utils/accounts';
import { AddressTxListTabs } from '../../../features/txs-list/tabs/AddressTxListTabs';
import { Flex, Stack } from '../../../ui/components';
import { PageTitle } from '../../_components/PageTitle';
import { AddressSummary } from './AddressSummary';
import { StxBalance } from './StxBalance';
import { TokenBalanceCard } from './TokenBalanceCard';
import { Wrapper } from './Wrapper';
import Loading from './loading';
import Skeleton from './skeleton';

Check warning on line 6 in src/app/address/[principal]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/page.tsx#L6

Added line #L6 was not covered by tests

export default function AddressPage({ params: { principal } }: any) {
const { data: balance } = useSuspenseAccountBalance(principal, { refetchOnWindowFocus: true });
const { data: nonces } = useAddressNonces({ address: principal });
const Page = dynamic(() => import('./PageClient'), {
loading: () => <Skeleton />,

Check warning on line 9 in src/app/address/[principal]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/page.tsx#L8-L9

Added lines #L8 - L9 were not covered by tests
ssr: false,
});

const hasTokenBalances = hasTokenBalance(balance);

return (
<>
<PageTitle>Address details</PageTitle>
<Wrapper>
<Stack gap={8}>
<AddressSummary
principal={principal}
hasTokenBalances={hasTokenBalances}
balances={balance}
lastExecutedTxNonce={nonces?.last_executed_tx_nonce}
/>
<AddressTxListTabs address={principal} />
</Stack>
{balance && (
<Stack gap={8}>
<StxBalance address={principal} />
<TokenBalanceCard address={principal} />
</Stack>
)}
</Wrapper>
<UnlockingScheduleModal balance={balance} />
</>
);
}
export default Page;

Check warning on line 13 in src/app/address/[principal]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/page.tsx#L13

Added line #L13 was not covered by tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SkeletonPageWithTagsAndTwoColumns } from '../../../common/components/loaders/skeleton-transaction';

export default function Loading() {
export default function Skeleton() {

Check warning on line 3 in src/app/address/[principal]/skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/skeleton.tsx#L3

Added line #L3 was not covered by tests
return <SkeletonPageWithTagsAndTwoColumns />;
}
69 changes: 69 additions & 0 deletions src/app/block/[hash]/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use client';

import dynamic from 'next/dynamic';
import * as React from 'react';

Check warning on line 4 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

import { BtcStxBlockLinks } from '../../../common/components/BtcStxBlockLinks';
import { KeyValueHorizontal } from '../../../common/components/KeyValueHorizontal';
import { Section } from '../../../common/components/Section';
import { Timestamp } from '../../../common/components/Timestamp';

Check warning on line 9 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L6-L9

Added lines #L6 - L9 were not covered by tests
import { TwoColumnPage } from '../../../common/components/TwoColumnPage';
import { Value } from '../../../common/components/Value';
import '../../../common/components/loaders/skeleton-text';
import { useSuspenseBlockByHash } from '../../../common/queries/useBlockByHash';
import { SkeletonTxsList } from '../../../features/txs-list/SkeletonTxsList';

Check warning on line 14 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L11-L14

Added lines #L11 - L14 were not covered by tests
import { Box, Flex, Grid } from '../../../ui/components';
import { PageTitle } from '../../_components/PageTitle';
import { TowColLayout } from '../../_components/TwoColLayout';
import { BlockBtcAnchorBlockCard } from './BlockBtcAnchorBlockCard';

Check warning on line 18 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L16-L18

Added lines #L16 - L18 were not covered by tests

const BlockTxsList = dynamic(
() => import('./tx-lists/BlockTxsList').then(mod => mod.BlockTxsList),

Check warning on line 21 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L21

Added line #L21 was not covered by tests
{
loading: () => (
<Section title={'Transactions'}>
<SkeletonTxsList />
</Section>
),
ssr: false,
}
);

export default function BlockPage({ params: { hash } }: any) {
const { data: block } = useSuspenseBlockByHash(hash, { refetchOnWindowFocus: true });

Check warning on line 33 in src/app/block/[hash]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/PageClient.tsx#L32-L33

Added lines #L32 - L33 were not covered by tests
const title = (block && `Block #${block.height.toLocaleString()}`) || '';
return (
<>
<PageTitle>{title}</PageTitle>
<TowColLayout>
<Section title="Summary">
<KeyValueHorizontal label={'Hash'} value={<Value>{hash}</Value>} copyValue={hash} />
{block && (
<>
<KeyValueHorizontal
label={'Block height'}
value={
<BtcStxBlockLinks
btcBlockHeight={block.burn_block_height}
stxBlockHeight={block.height}
stxBlockHash={block.hash}
/>
}
/>
<KeyValueHorizontal
label={'Mined'}
value={<Timestamp ts={block.burn_block_time} />}
/>
<KeyValueHorizontal
label={'Transactions'}
value={<Value>{block.txs.length}</Value>}
/>
</>
)}
</Section>
<BlockBtcAnchorBlockCard />
</TowColLayout>
<BlockTxsList blockHash={hash} />
</>
);
}
68 changes: 6 additions & 62 deletions src/app/block/[hash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,11 @@
import dynamic from 'next/dynamic';
import * as React from 'react';

import { BtcStxBlockLinks } from '../../../common/components/BtcStxBlockLinks';
import { KeyValueHorizontal } from '../../../common/components/KeyValueHorizontal';
import { Section } from '../../../common/components/Section';
import { Timestamp } from '../../../common/components/Timestamp';
import { TwoColumnPage } from '../../../common/components/TwoColumnPage';
import { Value } from '../../../common/components/Value';
import '../../../common/components/loaders/skeleton-text';
import { useSuspenseBlockByHash } from '../../../common/queries/useBlockByHash';
import { SkeletonTxsList } from '../../../features/txs-list/SkeletonTxsList';
import { Box, Flex, Grid } from '../../../ui/components';
import { PageTitle } from '../../_components/PageTitle';
import { TowColLayout } from '../../_components/TwoColLayout';
import { BlockBtcAnchorBlockCard } from './BlockBtcAnchorBlockCard';
import Skeleton from './skeleton';

Check warning on line 6 in src/app/block/[hash]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/page.tsx#L6

Added line #L6 was not covered by tests

const BlockTxsList = dynamic(
() => import('./tx-lists/BlockTxsList').then(mod => mod.BlockTxsList),
{
loading: () => (
<Section title={'Transactions'}>
<SkeletonTxsList />
</Section>
),
ssr: false,
}
);
const Page = dynamic(() => import('./PageClient'), {
loading: () => <Skeleton />,

Check warning on line 9 in src/app/block/[hash]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/page.tsx#L8-L9

Added lines #L8 - L9 were not covered by tests
ssr: false,
});

export default function BlockPage({ params: { hash } }: any) {
const { data: block } = useSuspenseBlockByHash(hash, { refetchOnWindowFocus: true });
const title = (block && `Block #${block.height.toLocaleString()}`) || '';
return (
<>
<PageTitle>{title}</PageTitle>
<TowColLayout>
<Section title="Summary">
<KeyValueHorizontal label={'Hash'} value={<Value>{hash}</Value>} copyValue={hash} />
{block && (
<>
<KeyValueHorizontal
label={'Block height'}
value={
<BtcStxBlockLinks
btcBlockHeight={block.burn_block_height}
stxBlockHeight={block.height}
stxBlockHash={block.hash}
/>
}
/>
<KeyValueHorizontal
label={'Mined'}
value={<Timestamp ts={block.burn_block_time} />}
/>
<KeyValueHorizontal
label={'Transactions'}
value={<Value>{block.txs.length}</Value>}
/>
</>
)}
</Section>
<BlockBtcAnchorBlockCard />
</TowColLayout>
<BlockTxsList blockHash={hash} />
</>
);
}
export default Page;

Check warning on line 13 in src/app/block/[hash]/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/page.tsx#L13

Added line #L13 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import { SkeletonPageWithTwoColumns } from '../../../common/components/loaders/skeleton-transaction';

export default function Loading() {
export default function Skeleton() {

Check warning on line 5 in src/app/block/[hash]/skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/skeleton.tsx#L5

Added line #L5 was not covered by tests
return <SkeletonPageWithTwoColumns />;
}
24 changes: 24 additions & 0 deletions src/app/blocks/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';

import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import * as React from 'react';

Check warning on line 5 in src/app/blocks/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/PageClient.tsx#L4-L5

Added lines #L4 - L5 were not covered by tests

import { SkeletonBlockList } from '../../common/components/loaders/skeleton-text';
import { PageTitle } from '../_components/PageTitle';

Check warning on line 8 in src/app/blocks/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/PageClient.tsx#L7-L8

Added lines #L7 - L8 were not covered by tests

const BlocksList = dynamic(() => import('../_components/BlockList').then(mod => mod.BlocksList), {
loading: () => <SkeletonBlockList />,

Check warning on line 11 in src/app/blocks/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/PageClient.tsx#L10-L11

Added lines #L10 - L11 were not covered by tests
ssr: false,
});

const BlocksPage: NextPage = () => {

Check warning on line 15 in src/app/blocks/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/PageClient.tsx#L15

Added line #L15 was not covered by tests
return (
<>
<PageTitle>Blocks</PageTitle>
<BlocksList />
</>
);
};

export default BlocksPage;

Check warning on line 24 in src/app/blocks/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/PageClient.tsx#L24

Added line #L24 was not covered by tests
21 changes: 4 additions & 17 deletions src/app/blocks/page.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
'use client';

import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import * as React from 'react';

import { SkeletonBlockList } from '../../common/components/loaders/skeleton-text';
import { Flex } from '../../ui/components';
import { PageTitle } from '../_components/PageTitle';
import Loading from './loading';
import Skeleton from './skeleton';

Check warning on line 6 in src/app/blocks/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/page.tsx#L6

Added line #L6 was not covered by tests

const BlocksList = dynamic(() => import('../_components/BlockList').then(mod => mod.BlocksList), {
loading: () => <SkeletonBlockList />,
const Page = dynamic(() => import('./PageClient'), {
loading: () => <Skeleton />,

Check warning on line 9 in src/app/blocks/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/page.tsx#L8-L9

Added lines #L8 - L9 were not covered by tests
ssr: false,
});

const BlocksPage: NextPage = () => {
return (
<>
<PageTitle>Blocks</PageTitle>
<BlocksList />
</>
);
};

export default BlocksPage;
export default Page;

Check warning on line 13 in src/app/blocks/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/page.tsx#L13

Added line #L13 was not covered by tests
7 changes: 3 additions & 4 deletions src/app/blocks/loading.tsx → src/app/blocks/skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import React from 'react';

import { SkeletonBlockList } from '../../common/components/loaders/skeleton-text';
import { Flex } from '../../ui/Flex';
import { Skeleton } from '../../ui/Skeleton';
import { Skeleton as SkeletonElement } from '../../ui/Skeleton';

Check warning on line 6 in src/app/blocks/skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/skeleton.tsx#L6

Added line #L6 was not covered by tests
import { PageTitle } from '../_components/PageTitle';

export default function Loading() {
export default function Skeleton() {

Check warning on line 9 in src/app/blocks/skeleton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/blocks/skeleton.tsx#L9

Added line #L9 was not covered by tests
return (
<>
<PageTitle>
<Skeleton width={'400px'} height={'43px'} />
<SkeletonElement width={'400px'} height={'43px'} />
</PageTitle>
<SkeletonBlockList />
</>
Expand Down
Loading

0 comments on commit ec54847

Please sign in to comment.