-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserList.tsx
74 lines (71 loc) · 1.77 KB
/
UserList.tsx
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
import { FC, ReactNode } from "react";
import { P, match } from "ts-pattern";
import { FragmentType, getFragmentData, graphql } from "../gql";
const UserListFragment = graphql(`
fragment UserListData on Query {
users {
id
name
type
... on Human {
registrationNumber
}
... on Robot {
modelNumber
}
}
}
`);
const UserList: FC<{
data: FragmentType<typeof UserListFragment>;
}> = ({ ...props }) => {
const data = getFragmentData(UserListFragment, props.data);
return (
<div>
{match(data)
.returnType<ReactNode>()
.with(
{
users: P.nonNullable,
},
({ users }) => (
<ul>
{users.map((user) => (
<li key={user.id}>
{match(user)
.returnType<ReactNode>()
.with(
{
__typename: "Human",
},
(user) => (
<>
"👤"
{user.name} ({user.registrationNumber})
</>
)
)
.with(
{
__typename: "Robot",
},
(user) => (
<>
"🤖"
{user.name} ({user.modelNumber})
</>
)
)
.exhaustive()}
</li>
))}
</ul>
)
)
.otherwise(() => (
<div>Something went wrong!</div>
))}
</div>
);
};
export default UserList;