|
1 | 1 | import { Deferred, Head } from '@inertiajs/react'; |
2 | 2 | import { motion } from 'framer-motion'; |
| 3 | +import type { PropsWithChildren } from 'react'; |
3 | 4 | import moment from 'moment-timezone'; |
4 | 5 | import { useMemo } from 'react'; |
5 | 6 | import { Leaderboard } from '@/components/race/leaderboard'; |
@@ -119,38 +120,94 @@ function RaceView({ race, isLast = false, matches, lpSeries, spotlight, stats }: |
119 | 120 | </div> |
120 | 121 | )} |
121 | 122 |
|
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 | + )} |
124 | 129 | </Deferred> |
125 | 130 |
|
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 | + )} |
128 | 137 | </Deferred> |
129 | 138 |
|
130 | 139 | <Deferred data="race_lp_series" fallback={<ChartSkeleton />}> |
131 | | - {() => <LpChart series={lpSeries} />} |
| 140 | + {() => ( |
| 141 | + <FadeIn> |
| 142 | + <LpChart series={lpSeries} /> |
| 143 | + </FadeIn> |
| 144 | + )} |
132 | 145 | </Deferred> |
133 | 146 |
|
134 | 147 | <Deferred data="race_matches" fallback={<MatchFeedSkeleton />}> |
135 | | - {() => <MatchFeed matches={matches} />} |
| 148 | + {() => ( |
| 149 | + <FadeIn> |
| 150 | + <MatchFeed matches={matches} /> |
| 151 | + </FadeIn> |
| 152 | + )} |
136 | 153 | </Deferred> |
137 | 154 | </div> |
138 | 155 | </div> |
139 | 156 | ); |
140 | 157 | } |
141 | 158 |
|
| 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 | + |
142 | 193 | function ChartSkeleton() { |
143 | 194 | 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> |
145 | 199 | ); |
146 | 200 | } |
147 | 201 |
|
148 | 202 | function MatchFeedSkeleton() { |
149 | 203 | 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> |
154 | 211 | </div> |
155 | 212 | ); |
156 | 213 | } |
|
0 commit comments