From 873676a5ec49921e9fd30c0487c82c4e4aa225d3 Mon Sep 17 00:00:00 2001 From: Peterbjx Date: Mon, 29 Apr 2024 14:04:25 +0800 Subject: [PATCH] feat: data cache --- public/favicon.ico | Bin 0 -> 5965 bytes src/app/[chain]/block/[hash]/page.tsx | 3 +++ src/app/[chain]/blocks/blockList.tsx | 2 +- src/app/[chain]/layout.tsx | 3 +++ src/app/[chain]/loading.tsx | 7 +++++++ src/app/[chain]/token/[tokenSymbol]/page.tsx | 3 +++ src/app/[chain]/tokens/page.tsx | 3 +++ src/app/api/revalidate/route.ts | 8 ++++++++ src/app/layout.tsx | 9 +++++++-- 9 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 public/favicon.ico create mode 100644 src/app/[chain]/layout.tsx create mode 100644 src/app/[chain]/loading.tsx create mode 100644 src/app/api/revalidate/route.ts diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..8cb7b995673279244fb753958501b068c990b0ce GIT binary patch literal 5965 zcmbVQ2{=@J-#(TmYslKhG)j~)i!sb(&7L(&S<9G(iJ6g^Y)wpA8YGmWY)RUzDV6Zp zWlbtdgc1^2lRe+j)6@67-}SuT_g>#zbLN~m=lWYE+IB!(whEr{j^ zq5(i#FUXHT^dYmLo@6g7T?aN(MU8Jfz&`Cad4y-9<71b(18AW!9aulBnsZn$mEwf@S6_I zo5k|OBM^asfog&3Y7Bob1PX`4A&_VU8Vv^#aAq)_MF@h^nTmfg7?GJof2tpg%AiBn z83~?@lPnz=DE3b;XnwzG>C9h|0%L{6qSe(fP-QCukxE~8LgjBu$VLPf zSqBE@4FgAF;Aor!3WZ04Z_RyR0+Gl+p;inMl@k1qP#hkq{x49lZb$?c;r|4ahH>WdM1UivyZlnVPy;h@ANq8&; zh1Sy4!of8?(F8aKhsD9QG;vrs#S=qDY7r?oA`bJ{dLst$>i$%hRMH1l{Ep-CiQ%jQ!r{ItpM9_i;kwRRr=bt5lH={Da=kK2xHOy_ery@%0wd|o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S5;SNS-f)l}GR-0}BxJB`-ZSLpW)bCv$ez;5AYS)^w@9LR}nS?Fv z5_REsBTJg!W{O#M&m=NX9H%!`UUCDSR`Iw0*o3Cdp#Ug+wS z&-e_s(scJT>ijp?ZB}yl_f9V_?9&kV*f4Oxt4BeV-94Hu^5(pBO-f*nx9fFcpS0sK zZ(aE&-DJnPRihjTPhaT=YwGfB(g_~^@uDQp6Vu;Y;2YImPk{q-Ozh~8`*VuM@T%i{ zfOGT2%x8z2uc!z4Qnt}%XTEGW@Im=`ubbs5cMEKR9y@1gZ?Xy!_&O=SYNID>@tmt^)GYk=UW>QA zX3Or7UR(P|ykbcP8qFJpT1An3i9qVsk#c=r=aX#{245x=(;%KWgL%K;}PE>zU{@4?V^DP zC+p*^_YQgw+J$qXxmgR%{duVh@QH4p0dexfWRI%2$PTPn;ZkXzEK=`XKwOId)g$E} z)b=!T(+BUe^|MtwE;kV}{8Gkqr0ZSv(QOmm1YR|&%7b2TrD!-i|AlCVTZi_cC$&0b zo<@OtE2^>FU1#nyM`1xhS&Qig%xqfU{6~{L0Zj(4U?@2WO?=5=-RrYf5~7w*GU~ zLqGP35nS20{+Wt7ANN5pFt;^vDiu90eHNfQsMOTWBE*(ibPJb*?|_Tc6YbxC&pe-Z zeS6x0+HWA9DlQjy`Qw|6m|_%%w0*)knKwY@diDUj-2lrqvy)qP;aBPsEw;%OP4hf- z1(MJ@jO?h^SL4xY_Jj~V>{1iZ_pEvh6V&A~d@ms_BGZtxDU!bo z*baCQIFVe{(P7DGrpS5o^C@+5tBxKqb=+Om;&YeFitVS@V72G`PpeDltpDL{ZftE- JaKPj2e*vyvSDOF; literal 0 HcmV?d00001 diff --git a/src/app/[chain]/block/[hash]/page.tsx b/src/app/[chain]/block/[hash]/page.tsx index e7d26702..275eee35 100644 --- a/src/app/[chain]/block/[hash]/page.tsx +++ b/src/app/[chain]/block/[hash]/page.tsx @@ -17,3 +17,6 @@ export default async function Block({ params }: { params: { hash: string; chain: console.log(data, 'data'); return ; } + +export const revalidate = 1; +export const dynamic = 'force-dynamic'; diff --git a/src/app/[chain]/blocks/blockList.tsx b/src/app/[chain]/blocks/blockList.tsx index b59139b8..4aad7db6 100644 --- a/src/app/[chain]/blocks/blockList.tsx +++ b/src/app/[chain]/blocks/blockList.tsx @@ -41,6 +41,7 @@ export default function BlockList({ SSRData }) { const [data, setData] = useState(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; @@ -71,7 +72,6 @@ export default function BlockList({ SSRData }) { [currentPage, data, defaultChain, totalPage], ); - const { chain } = useParams(); const [timeFormat, setTimeFormat] = useState('Age'); const columns = useMemo>(() => { return getColumns({ diff --git a/src/app/[chain]/layout.tsx b/src/app/[chain]/layout.tsx new file mode 100644 index 00000000..1ad5b9a4 --- /dev/null +++ b/src/app/[chain]/layout.tsx @@ -0,0 +1,3 @@ +export default function Layout({ children }) { + return
{children}
; +} diff --git a/src/app/[chain]/loading.tsx b/src/app/[chain]/loading.tsx new file mode 100644 index 00000000..2b09afda --- /dev/null +++ b/src/app/[chain]/loading.tsx @@ -0,0 +1,7 @@ +'use client'; +import { useIsGovernance } from '@_hooks/useIsPath'; +import { Skeleton } from 'antd'; +export default function Loading() { + const isGovernance = useIsGovernance(); + return !isGovernance && ; +} diff --git a/src/app/[chain]/token/[tokenSymbol]/page.tsx b/src/app/[chain]/token/[tokenSymbol]/page.tsx index fdd5e76d..ac76bb61 100644 --- a/src/app/[chain]/token/[tokenSymbol]/page.tsx +++ b/src/app/[chain]/token/[tokenSymbol]/page.tsx @@ -25,3 +25,6 @@ export default async function TokenSymbol({ ); } + +export const revalidate = 1; +export const dynamic = 'force-dynamic'; diff --git a/src/app/[chain]/tokens/page.tsx b/src/app/[chain]/tokens/page.tsx index aac42861..15601cca 100644 --- a/src/app/[chain]/tokens/page.tsx +++ b/src/app/[chain]/tokens/page.tsx @@ -22,3 +22,6 @@ export default async function TokensPage({ params }: { params: ChainId }) { }); return ; } + +export const revalidate = 1; +export const dynamic = 'force-dynamic'; diff --git a/src/app/api/revalidate/route.ts b/src/app/api/revalidate/route.ts new file mode 100644 index 00000000..f459aa59 --- /dev/null +++ b/src/app/api/revalidate/route.ts @@ -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() }); +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 878c7957..3e029540 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -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)); @@ -37,6 +38,7 @@ 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(); @@ -44,6 +46,9 @@ export default async function RootLayout({ children }: { children: React.ReactNo const { headerMenuList, footerMenuList, chainList, networkList } = await fetchCMS(); return ( + + +