11import { Link } from "react-router" ;
2- import { Suspense , use } from "react" ;
2+ import { Suspense } from "react" ;
33
44import iconsHref from "~/icons.svg" ;
55import { getStats } from "~/modules/stats" ;
66import type { Route } from "./+types/splash" ;
77
8- export let loader = async ( ) => {
9- const stats = getStats ( ) ;
10- return { stats } ;
11- } ;
12-
138// TODO: target="_blank" for discord?
149
1510export const meta : Route . MetaFunction = ( { matches } ) => {
@@ -110,7 +105,7 @@ const adventures: Adventure[] = [
110105 } ,
111106] ;
112107
113- export default function Home ( { loaderData } : Route . ComponentProps ) {
108+ export function ServerComponent ( ) {
114109 return (
115110 < main className = "flex min-h-full w-full flex-col items-center justify-center dark:bg-gray-900" >
116111 < section className = "from-23% via-82% flex w-full flex-col items-center gap-y-12 bg-gradient-to-b from-[#CCD2DE] via-[#D9DDE6] to-white to-100% py-[96px] dark:from-[#595F6C] dark:via-[#202228] dark:via-65% dark:to-gray-900 md:py-[160px]" >
@@ -212,28 +207,8 @@ export default function Home({ loaderData }: Route.ComponentProps) {
212207 </ div >
213208 </ section >
214209 < section className = "grid w-full place-content-center p-12" >
215- < Suspense fallback = { null } >
216- < Await resolve = { loaderData . stats } >
217- { ( stats ) => (
218- < dl className = "grid grid-cols-1 gap-x-6 gap-y-16 md:grid-cols-2" >
219- { stats . map ( ( { svgId, count, label } ) => (
220- < div key = { svgId } className = "flex w-[308px] gap-2" >
221- < svg className = "h-8 w-8 text-gray-600" aria-hidden = "true" >
222- < use href = { `${ iconsHref } #${ svgId } ` } />
223- </ svg >
224- < div className = "flex flex-col" >
225- < dd className = "text-2xl font-semibold text-gray-700 dark:text-gray-200" >
226- { count ?. toLocaleString ( "en-US" ) }
227- </ dd >
228- < dt className = "text-gray-500 dark:text-gray-400" >
229- { label }
230- </ dt >
231- </ div >
232- </ div >
233- ) ) }
234- </ dl >
235- ) }
236- </ Await >
210+ < Suspense fallback = { < div > loading...</ div > } >
211+ < Stats />
237212 </ Suspense >
238213 </ section >
239214 < section className = "grid h-[205px] w-full place-content-center place-items-center gap-y-6 bg-gray-50 p-12 dark:bg-black" >
@@ -252,13 +227,24 @@ export default function Home({ loaderData }: Route.ComponentProps) {
252227 ) ;
253228}
254229
255- function Await < T > ( {
256- children,
257- resolve,
258- } : {
259- children : ( r : T ) => React . ReactNode ;
260- resolve : Promise < T > ;
261- } ) {
262- const result = use ( resolve ) ;
263- return < > { children ( result ) } </ > ;
230+ async function Stats ( ) {
231+ const stats = await getStats ( ) ;
232+
233+ return (
234+ < dl className = "grid grid-cols-1 gap-x-6 gap-y-16 md:grid-cols-2" >
235+ { stats . map ( ( { svgId, count, label } ) => (
236+ < div key = { svgId } className = "flex w-[308px] gap-2" >
237+ < svg className = "h-8 w-8 text-gray-600" aria-hidden = "true" >
238+ < use href = { `${ iconsHref } #${ svgId } ` } />
239+ </ svg >
240+ < div className = "flex flex-col" >
241+ < dd className = "text-2xl font-semibold text-gray-700 dark:text-gray-200" >
242+ { count ?. toLocaleString ( "en-US" ) }
243+ </ dd >
244+ < dt className = "text-gray-500 dark:text-gray-400" > { label } </ dt >
245+ </ div >
246+ </ div >
247+ ) ) }
248+ </ dl >
249+ ) ;
264250}
0 commit comments