Skip to content

Commit

Permalink
Merge pull request #321 from AElfProject/feature/refactor-2.0.0-Block…
Browse files Browse the repository at this point in the history
…chain

feat: data cache
  • Loading branch information
Peterbjx committed Apr 29, 2024
2 parents caa167f + 873676a commit b4a67bc
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 3 deletions.
Binary file added public/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions src/app/[chain]/block/[hash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ export default async function Block({ params }: { params: { hash: string; chain:
console.log(data, 'data');
return <Detail SSRData={data} />;
}

export const revalidate = 1;
export const dynamic = 'force-dynamic';
2 changes: 1 addition & 1 deletion src/app/[chain]/blocks/blockList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function BlockList({ SSRData }) {
const [data, setData] = useState<IBlocksResponseItem[]>(SSRData.blocks);
const { defaultChain } = useAppSelector((state) => state.getChainId);
const totalPage = Math.floor((total + pageSize - 1) / pageSize) || 1;
const { chain } = useParams();
const fetchData = useCallback(
async (pageSize, type: pageType) => {
let blockHeight;
Expand Down Expand Up @@ -71,7 +72,6 @@ export default function BlockList({ SSRData }) {
[currentPage, data, defaultChain, totalPage],
);

const { chain } = useParams();
const [timeFormat, setTimeFormat] = useState<string>('Age');
const columns = useMemo<ColumnsType<IBlocksResponseItem>>(() => {
return getColumns({
Expand Down
3 changes: 3 additions & 0 deletions src/app/[chain]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Layout({ children }) {
return <div>{children}</div>;
}
7 changes: 7 additions & 0 deletions src/app/[chain]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';
import { useIsGovernance } from '@_hooks/useIsPath';
import { Skeleton } from 'antd';
export default function Loading() {
const isGovernance = useIsGovernance();
return !isGovernance && <Skeleton className="main-skeleton top-[104px] h-[calc(100vh-474px)]" />;
}
3 changes: 3 additions & 0 deletions src/app/[chain]/token/[tokenSymbol]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ export default async function TokenSymbol({
</div>
);
}

export const revalidate = 1;
export const dynamic = 'force-dynamic';
3 changes: 3 additions & 0 deletions src/app/[chain]/tokens/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ export default async function TokensPage({ params }: { params: ChainId }) {
});
return <TokensList SSRData={data} />;
}

export const revalidate = 1;
export const dynamic = 'force-dynamic';
8 changes: 8 additions & 0 deletions src/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NextRequest } from 'next/server';
import { revalidateTag } from 'next/cache';

export async function GET(request: NextRequest) {
const tag = request.nextUrl.searchParams.get('tag');
revalidateTag(tag || '');
return Response.json({ revalidated: true, now: Date.now() });
}
9 changes: 7 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import StyleRegistry from './StyleRegistry';
import { fetchCMS } from '@_api/fetchCMS';
import { PublicEnvProvider } from 'next-runtime-env';
import type { Viewport } from 'next';
import { revalidatePath } from 'next/cache';

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
title: 'AELF Block Explorer',
description: 'AELF explorer',
};
async function fetchData() {
await new Promise((resolve) => setTimeout(resolve, 1000));
Expand All @@ -37,13 +38,17 @@ async function fetchData() {
}

export default async function RootLayout({ children }: { children: React.ReactNode }) {
revalidatePath('/', 'layout');
const data = await fetchData();
const { price, previousPrice } = data;
const headersList = headers();
const isMobile = isMobileOnServer(headersList);
const { headerMenuList, footerMenuList, chainList, networkList } = await fetchCMS();
return (
<html lang="en">
<head>
<link rel="icon" href="/favicon.ico" />
</head>
<body>
<div className="relative box-border min-h-screen bg-global-grey">
<PublicEnvProvider>
Expand Down

0 comments on commit b4a67bc

Please sign in to comment.