|
1 | 1 | // Copyright 2022 MFB Technologies, Inc.
|
2 | 2 |
|
3 | 3 | import './App.css';
|
4 |
| -import { AsyncRequestStatus, createAsyncRenderer, LoadingSpinner } from "@mfbtech/react-async-renderer" |
5 |
| -import { useState } from 'react'; |
6 |
| - |
7 |
| -/* |
8 |
| -createAsyncUiModelRenderer |
9 |
| -rtkqResultsToStatusError |
10 |
| -composeAsyncUiModel |
11 |
| -getCascadedAsyncState |
12 |
| -getOptimisticAsyncLoadState |
13 |
| -*/ |
| 4 | +import { LoadingSpinner } from "@mfbtech/react-async-renderer" |
| 5 | +import { AsyncRendererExample } from './AsyncRendererExample'; |
| 6 | +import { CascadedAsyncStateExample } from './CascadedAsyncStateExample'; |
14 | 7 |
|
15 | 8 | export function App() {
|
16 |
| - const [currentAsyncRequestState, setCurrentAsyncRequestState] = useState(AsyncRequestStatus.INIT) |
17 |
| - const asyncRequestError = currentAsyncRequestState === AsyncRequestStatus.ERROR ? "some error occurred!" : null |
18 |
| - const asyncRequestData = currentAsyncRequestState === AsyncRequestStatus.FULFILLED ? { data: "my data" } : null |
19 |
| - const renderer = createAsyncRenderer({ |
20 |
| - status: currentAsyncRequestState, |
21 |
| - error: asyncRequestError, |
22 |
| - onCompletedSuccessfullyArgs: asyncRequestData, |
23 |
| - }) |
24 |
| - |
25 | 9 | return (
|
26 | 10 | <div className="App">
|
27 |
| - <h1>@mfbtech/react-async-renderer</h1> |
28 |
| - <div> |
29 |
| - <h2>Async renderer example</h2> |
| 11 | + <div className='wrapper'> |
| 12 | + <h1>@mfbtech/react-async-renderer</h1> |
| 13 | + <AsyncRendererExample /> |
| 14 | + <CascadedAsyncStateExample /> |
30 | 15 | <div>
|
31 |
| - <label htmlFor="asyncRequestStatus">Status of the long running process:</label> |
32 |
| - <select |
33 |
| - value={currentAsyncRequestState} |
34 |
| - onChange={(e) => { |
35 |
| - setCurrentAsyncRequestState(e.currentTarget.value as AsyncRequestStatus) |
36 |
| - }} |
37 |
| - id="asyncRequestStatus"> |
38 |
| - { |
39 |
| - Object.entries(AsyncRequestStatus).map(([name, value]) => { |
40 |
| - return ( |
41 |
| - <option key={value} value={value}>{name}</option> |
42 |
| - ) |
43 |
| - }) |
44 |
| - } |
45 |
| - </select> |
| 16 | + <h2>Default loading spinner example</h2> |
| 17 | + <LoadingSpinner /> |
| 18 | + <p>Don't stare at it too long, it will drive you nuts! 🤪</p> |
46 | 19 | </div>
|
47 |
| - <div> |
48 |
| - {renderer((args) => { |
49 |
| - return ( |
50 |
| - <p className='success'>{args.data}</p> |
51 |
| - ) |
52 |
| - }, |
53 |
| - { |
54 |
| - onInit: () => (<p className='info'>Waiting for long running process to start...</p>), |
55 |
| - onLoading: () => (<p className='info'>custom spinner...</p>), |
56 |
| - onCompletedWithError: (props) => (<p className='error'>{props.errorMessage ?? "error"}</p>) |
57 |
| - })} |
58 |
| - </div> |
59 |
| - </div> |
60 |
| - <div> |
61 |
| - <h2>Default loading spinner example</h2> |
62 |
| - <LoadingSpinner /> |
63 | 20 | </div>
|
64 | 21 | </div>
|
65 | 22 | );
|
|
0 commit comments