Skip to content

Commit cb8e534

Browse files
committed
optimize speed
1 parent 7b4ac1b commit cb8e534

2 files changed

Lines changed: 70 additions & 13 deletions

File tree

resources/js/components/race/race-header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export function RaceHeader({ race, isLast = false }: Props) {
5252
style={{ minHeight: 'min(88svh, 700px)', paddingTop: '5rem', paddingBottom: '5.5rem' }}
5353
>
5454
<motion.div
55-
initial={{ opacity: 0, y: 20 }}
55+
initial={{ opacity: 0, y: 10 }}
5656
animate={{ opacity: 1, y: 0 }}
57-
transition={{ duration: 0.6, ease: [0.22, 1, 0.36, 1] }}
57+
transition={{ duration: 0.3, ease: [0.22, 1, 0.36, 1] }}
5858
className="max-w-xl"
5959
>
6060
{/* Eyebrow */}

resources/js/pages/home.tsx

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Deferred, Head } from '@inertiajs/react';
22
import { motion } from 'framer-motion';
3+
import type { PropsWithChildren } from 'react';
34
import moment from 'moment-timezone';
45
import { useMemo } from 'react';
56
import { Leaderboard } from '@/components/race/leaderboard';
@@ -119,38 +120,94 @@ function RaceView({ race, isLast = false, matches, lpSeries, spotlight, stats }:
119120
</div>
120121
)}
121122

122-
<Deferred data="race_stats" fallback={null}>
123-
{() => stats && <RaceStatCards stats={stats} participantCount={race.leaderboard.length} />}
123+
<Deferred data="race_stats" fallback={<StatCardsSkeleton />}>
124+
{() => stats && (
125+
<FadeIn>
126+
<RaceStatCards stats={stats} participantCount={race.leaderboard.length} />
127+
</FadeIn>
128+
)}
124129
</Deferred>
125130

126-
<Deferred data="race_spotlight" fallback={null}>
127-
{() => spotlight.length > 0 && <StreamerSpotlight streamers={spotlight} />}
131+
<Deferred data="race_spotlight" fallback={<SpotlightSkeleton />}>
132+
{() => spotlight.length > 0 && (
133+
<FadeIn>
134+
<StreamerSpotlight streamers={spotlight} />
135+
</FadeIn>
136+
)}
128137
</Deferred>
129138

130139
<Deferred data="race_lp_series" fallback={<ChartSkeleton />}>
131-
{() => <LpChart series={lpSeries} />}
140+
{() => (
141+
<FadeIn>
142+
<LpChart series={lpSeries} />
143+
</FadeIn>
144+
)}
132145
</Deferred>
133146

134147
<Deferred data="race_matches" fallback={<MatchFeedSkeleton />}>
135-
{() => <MatchFeed matches={matches} />}
148+
{() => (
149+
<FadeIn>
150+
<MatchFeed matches={matches} />
151+
</FadeIn>
152+
)}
136153
</Deferred>
137154
</div>
138155
</div>
139156
);
140157
}
141158

159+
function FadeIn({ children }: PropsWithChildren) {
160+
return (
161+
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: 0.4 }}>
162+
{children}
163+
</motion.div>
164+
);
165+
}
166+
167+
function StatCardsSkeleton() {
168+
return (
169+
<div>
170+
<div className="h-3 w-24 rounded bg-white/[0.04] mb-4 animate-pulse" />
171+
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3">
172+
{Array.from({ length: 8 }).map((_, i) => (
173+
<div key={i} className="h-[76px] rounded-lg bg-white/[0.03] border border-white/5 animate-pulse" />
174+
))}
175+
</div>
176+
</div>
177+
);
178+
}
179+
180+
function SpotlightSkeleton() {
181+
return (
182+
<div className="rounded-xl border border-white/5 overflow-hidden">
183+
<div className="flex gap-1.5 px-4 pt-4 pb-3 border-b border-white/5">
184+
{Array.from({ length: 3 }).map((_, i) => (
185+
<div key={i} className="h-7 w-20 rounded-md bg-white/[0.04] animate-pulse" />
186+
))}
187+
</div>
188+
<div className="h-56 bg-white/[0.02] animate-pulse" />
189+
</div>
190+
);
191+
}
192+
142193
function ChartSkeleton() {
143194
return (
144-
<div className="h-48 rounded-lg bg-white/[0.03] border border-white/5 animate-pulse" />
195+
<div>
196+
<div className="h-3 w-20 rounded bg-white/[0.04] mb-4 animate-pulse" />
197+
<div className="h-48 rounded-lg bg-white/[0.03] border border-white/5 animate-pulse" />
198+
</div>
145199
);
146200
}
147201

148202
function MatchFeedSkeleton() {
149203
return (
150-
<div className="space-y-2">
151-
{Array.from({ length: 5 }).map((_, i) => (
152-
<div key={i} className="h-14 rounded-lg bg-white/[0.03] border border-white/5 animate-pulse" />
153-
))}
204+
<div>
205+
<div className="h-3 w-24 rounded bg-white/[0.04] mb-4 animate-pulse" />
206+
<div className="space-y-2">
207+
{Array.from({ length: 5 }).map((_, i) => (
208+
<div key={i} className="h-14 rounded-lg bg-white/[0.03] border border-white/5 animate-pulse" />
209+
))}
210+
</div>
154211
</div>
155212
);
156213
}

0 commit comments

Comments
 (0)