()
| 15 | }; |
| 16 | |
| 17 | const App = () => { |
| 18 | const [ttl, { loading: ttlLoading, error: ttlError }] = createResource(() => 'TTL', fetchQuotes); |
| 19 | const [swr, { loading: swrLoading, error: swrError }] = createResource(() => 'SWR', fetchQuotes); |
| 20 | const [both, { loading: bothLoading, error: bothError }] = createResource(() => 'TTL + SWR', fetchQuotes); |
| 21 | const [none, { loading: noneLoading, error: noneError }] = createResource(() => 'NO CACHING', fetchQuotes); |
| 22 | |
| 23 | const renderQuote = (title: string, type: string, result: () => QuoteResult | undefined, loading: boolean, error: any) => ( |
| 24 | <Show when={!loading} fallback={<div>Loading...</div>}> |
| 25 | {error ? ( |
| 26 | <div>Error: {error.message}</div> |
| 27 | ) : ( |
| 28 | <Quote title={title} type={type} result={result()} /> |
| 29 | )} |
| 30 | </Show> |
| 31 | ); |
| 32 | const refreshPage = () => { |
| 33 | window.location.reload(); |
| 34 | }; |
| 35 | return ( |
| 36 | <main class="flex min-h-screen flex-col items-center justify-start p-8 md:p-24"> |
| 37 | <h1 class="text-3xl text-slate-800 text-black">Accelerated Quotes</h1> |
| 38 | <p class="text-xl text-slate-800 mb-10"> |
| 39 | Retrieves the most recently added quote with and without caching enabled |
| 40 | </p> |
| 41 | <button class="mb-9 focus:outline-none text-white bg-green-700 hover:bg-green-800 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 bg-green-600 hover:bg-green-700 focus:ring-green-800" onClick={refreshPage}>Refresh Page</button> |
| 42 | <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"> |
| 43 | <Suspense fallback={<div class="news-list-nav">Loading...</div>}> |
| 44 | {renderQuote("Cached Quote", "TTL", ttl, ttlLoading, ttlError)} |
| 45 | {renderQuote("Cached Quote", "SWR", swr, swrLoading, swrError)} |
| 46 | { renderQuote("Cached Quote", "TTL + SWR", both, bothLoading, bothError)} |
| 47 | {renderQuote("Quote", "NO CACHING", none, noneLoading, noneError)} |
| 48 | </Suspense> |
| 49 | </div> |
| 50 | </main> |
| 51 | ); |
| 52 | }; |
| 53 | |
| 54 | export default App; |
| 55 |
nothing calls this directly
no test coverage detected