11import HeroEpochCard from '@/components/Hero/HeroEpochCard' ;
2+ import { fN } from '@/lib/utils' ;
23import * as types from '@/typedefs/blockchain' ;
34import { Skeleton } from '@heroui/skeleton' ;
45import { round } from 'lodash' ;
5- import { Suspense } from 'react' ;
6+ import { Suspense , cache , memo } from 'react' ;
67import R1MintedLastEpoch from '../R1MintedLastEpoch' ;
78import { BorderedCard } from '../shared/cards/BorderedCard' ;
89import { CardHorizontal } from '../shared/cards/CardHorizontal' ;
910import R1TotalSupply from '../shared/R1TotalSupply' ;
1011
12+ // Memoized component for props-dependent parts
13+ const HeroStats = memo (
14+ ( { nodesTotalItems, resourcesTotal } : { nodesTotalItems : number ; resourcesTotal : types . ResourcesTotal } ) => (
15+ < >
16+ < CardHorizontal label = "Active Nodes" value = { nodesTotalItems } isFlexible widthClasses = "min-w-[196px]" />
17+
18+ < CardHorizontal
19+ label = "CPU Cores Available"
20+ value = { round ( resourcesTotal . cpu_cores_avail , 1 ) }
21+ isFlexible
22+ widthClasses = "min-w-[288px]"
23+ />
24+
25+ < CardHorizontal
26+ label = "Memory Available"
27+ value = {
28+ < div >
29+ { fN ( resourcesTotal . mem_avail ) } < span className = "text-slate-500" > GB</ span >
30+ </ div >
31+ }
32+ isFlexible
33+ widthClasses = "min-w-[314px]"
34+ />
35+
36+ < CardHorizontal
37+ label = "Disk Available"
38+ value = {
39+ < div >
40+ { fN ( resourcesTotal . disk_avail ) } < span className = "text-slate-500" > GB</ span >
41+ </ div >
42+ }
43+ isFlexible
44+ widthClasses = "min-w-[290px]"
45+ />
46+ </ >
47+ ) ,
48+ ) ;
49+
50+ HeroStats . displayName = 'HeroStats' ;
51+
52+ const CachedHeroContent = cache ( async ( ) => (
53+ < >
54+ < CardHorizontal
55+ label = {
56+ < div >
57+ < span className = "font-semibold text-primary" > $R1</ span > total supply
58+ </ div >
59+ }
60+ value = { < R1TotalSupply /> }
61+ isFlexible
62+ widthClasses = "min-[420px]:min-w-[330px] md:max-w-[350px]"
63+ />
64+
65+ < Suspense fallback = { < Skeleton className = "min-h-[76px] w-full min-w-[300px] flex-1 rounded-xl md:max-w-[320px]" /> } >
66+ < CardHorizontal
67+ label = {
68+ < div >
69+ < span className = "font-semibold text-primary" > $R1</ span > minted last epoch
70+ </ div >
71+ }
72+ value = { < R1MintedLastEpoch /> }
73+ isFlexible
74+ widthClasses = "min-w-[300px]"
75+ />
76+ </ Suspense >
77+
78+ < HeroEpochCard />
79+ </ >
80+ ) ) ;
81+
1182export default async function Hero ( {
1283 nodesTotalItems,
1384 resourcesTotal,
@@ -21,68 +92,8 @@ export default async function Hero({
2192 < div className = "card-title-big font-bold" > Nodes</ div >
2293
2394 < div className = "flexible-row" >
24- < CardHorizontal label = "Active Nodes" value = { nodesTotalItems } isFlexible widthClasses = "min-w-[200px]" />
25-
26- < CardHorizontal
27- label = "CPU Cores Available"
28- value = {
29- < div >
30- { round ( resourcesTotal . cpu_cores_avail , 0 ) } /{ resourcesTotal . cpu_cores }
31- </ div >
32- }
33- isFlexible
34- widthClasses = "min-w-[290px]"
35- />
36-
37- < CardHorizontal
38- label = "Memory Available (GB)"
39- value = {
40- < div >
41- { round ( resourcesTotal . mem_avail , 0 ) } /{ round ( resourcesTotal . mem_total , 0 ) }
42- </ div >
43- }
44- isFlexible
45- widthClasses = "min-w-[308px]"
46- />
47-
48- < CardHorizontal
49- label = "Disk Available (GB)"
50- value = {
51- < div >
52- { round ( resourcesTotal . disk_avail , 0 ) } /{ round ( resourcesTotal . disk_total , 0 ) }
53- </ div >
54- }
55- isFlexible
56- widthClasses = "min-w-[296px]"
57- />
58-
59- < CardHorizontal
60- label = {
61- < div >
62- < span className = "font-semibold text-primary" > $R1</ span > total supply
63- </ div >
64- }
65- value = { < R1TotalSupply /> }
66- isFlexible
67- widthClasses = "min-[420px]:min-w-[330px] md:max-w-[350px]"
68- />
69-
70- < Suspense
71- fallback = { < Skeleton className = "min-h-[76px] w-full min-w-[340px] flex-1 rounded-xl md:max-w-[320px]" /> }
72- >
73- < CardHorizontal
74- label = {
75- < div >
76- < span className = "font-semibold text-primary" > $R1</ span > minted last epoch
77- </ div >
78- }
79- value = { < R1MintedLastEpoch /> }
80- isFlexible
81- widthClasses = "min-w-[340px]"
82- />
83- </ Suspense >
84-
85- < HeroEpochCard />
95+ < HeroStats nodesTotalItems = { nodesTotalItems } resourcesTotal = { resourcesTotal } />
96+ < CachedHeroContent />
8697 </ div >
8798 </ BorderedCard >
8899 </ div >
0 commit comments