Skip to content

Commit a8b85c3

Browse files
committed
example/App: update app to use example components, update styling
1 parent 73e4ea3 commit a8b85c3

File tree

2 files changed

+16
-61
lines changed

2 files changed

+16
-61
lines changed

example/src/App.css

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
*/
44

55
.App {
6+
display: flex;
7+
flex-direction: column;
8+
margin: auto;
69
text-align: center;
10+
max-width: 1024px;
711
}
8-
.success {
9-
color: green
10-
}
11-
.info {
12-
color: blue;
13-
}
14-
.error {
15-
color: red;
12+
.wrapper {
13+
margin: auto 10px;
1614
}

example/src/App.tsx

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,22 @@
11
// Copyright 2022 MFB Technologies, Inc.
22

33
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';
147

158
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-
259
return (
2610
<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 />
3015
<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>
4619
</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 />
6320
</div>
6421
</div>
6522
);

0 commit comments

Comments
 (0)