-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
CreateReaction.tsx
42 lines (39 loc) · 1.12 KB
/
CreateReaction.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
import { useController, useCache } from 'rest-hooks';
import { UserResource } from 'resources/User';
import { v4 as uuid } from 'uuid';
import { Reaction, ReactionResource, contentToIcon } from 'resources/Reaction';
import { Issue } from 'resources/Issue';
import { Tag } from 'antd';
const { CheckableTag } = Tag;
export function CreateReaction({
content,
reactions = [],
issue,
}: {
reactions: Reaction[];
content: keyof typeof contentToIcon;
issue: Issue;
}) {
const { fetch } = useController();
const currentUser = useCache(UserResource.current);
const userReaction: Reaction | undefined =
currentUser &&
reactions.find((reaction) => reaction.user.login === currentUser.login);
const handleClick = () => {
if (userReaction || !currentUser) return;
fetch(
ReactionResource.create,
{
owner: issue.owner,
number: issue.number,
repo: issue.repo,
},
{ content, id: uuid() as any as number, user: currentUser.login as any },
);
};
return (
<CheckableTag checked={false} onChange={handleClick}>
{contentToIcon[content]}
</CheckableTag>
);
}