forked from isaacplmann/sturdy-uis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
76 lines (72 loc) · 2.23 KB
/
App.tsx
File metadata and controls
76 lines (72 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { useMachine } from '@xstate/react';
import React from 'react';
import { fetchPeople, fetchPlanets } from './api';
import { List } from './List';
import './App.css';
import { matchingMachine } from './machines/matching';
export interface Person {
name: string;
homeworld: string;
}
function App() {
const [matchingState, sendToMatchingMachine] = useMachine(matchingMachine, {
guards: {
isCorrect: ctx => {
return ctx.topSelectedItem.homeworld === ctx.bottomSelectedItem.url;
}
}
});
return (
<div className='App'>
{matchingState.matches('quiz.answering') ? (
<>
<button onClick={() => sendToMatchingMachine({ type: 'CONTINUE' })}>
Continue
</button>
<List
fetchData={fetchPeople}
selectedItem={matchingState.context.topSelectedItem}
onSelection={selectedItem => {
sendToMatchingMachine({ type: 'SELECT_TOP', selectedItem });
}}
></List>
<hr />
<List
fetchData={fetchPlanets}
selectedItem={matchingState.context.bottomSelectedItem}
onSelection={selectedItem => {
sendToMatchingMachine({ type: 'SELECT_BOTTOM', selectedItem });
}}
></List>
</>
) : null}
{matchingState.matches('quiz.verifying') ? (
<>
<p>
You chose{' '}
{matchingState.context.topSelectedItem &&
matchingState.context.topSelectedItem.name}{' '}
and{' '}
{matchingState.context.bottomSelectedItem &&
matchingState.context.bottomSelectedItem.name}
</p>
<button
onClick={() => sendToMatchingMachine({ type: 'CHANGE_ANSWERS' })}
>
Change Answers
</button>
<button onClick={() => sendToMatchingMachine({ type: 'SUBMIT' })}>
Submit
</button>
</>
) : null}
{matchingState.matches('submitted.correct') ? (
<p>The Force is strong with this one.</p>
) : null}
{matchingState.matches('submitted.incorrect') ? (
<p>Do or do not. There is no try.</p>
) : null}
</div>
);
}
export default App;