-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Reaction.tsx
80 lines (70 loc) · 1.92 KB
/
Reaction.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
75
76
77
78
79
80
import { HeartOutlined } from '@ant-design/icons';
import { createGithubResource, GithubEntity } from './Base';
import PreviewEndpoint from './PreviewEndpoint';
import { User } from './User';
export type ReactionType =
| '+1'
| '-1'
| 'laugh'
| 'confused'
| 'heart'
| 'hooray'
| 'eyes'
| 'rocket';
const Plus = (...args: any[]): any => '👍';
const Minus = (...args: any[]): any => '👎';
const Party = (...args: any[]): any => '🎉';
const Confused = (...args: any[]): any => '😕';
const Laugh = (...args: any[]): any => '😄';
const Rocket = (...args: any[]): any => '🚀';
const Eyes = (...args: any[]): any => '👀';
export const contentToIcon = {
'+1': <Plus />,
'-1': <Minus />,
laugh: <Laugh />,
confused: <Confused />,
heart: <HeartOutlined />,
hooray: <Party />,
rocket: <Rocket />,
eyes: <Eyes />,
} as const;
export class Reaction extends GithubEntity {
readonly user: User = User.fromJS({});
readonly content: ReactionType = '+1';
readonly createdAt: Date = new Date(0);
get contentIcon() {
return contentToIcon[this.content];
}
pk() {
return this.id?.toString();
}
static schema = {
user: User,
createdAt: Date,
};
}
const base = createGithubResource(
'/repos/:owner/:repo/issues/:number/reactions/:id' as const,
Reaction,
PreviewEndpoint,
);
export const ReactionResource = {
...base,
getByComment: base.getList.extend({
urlRoot: 'repos/:owner/:repo/issues/comments/:comment/reactions' as const,
body: undefined,
}),
create: base.create.extend({
update: (newId: string, params: any) => ({
[base.getList.key(params)]: ({ results = [], ...rest } = {}) => ({
results: [...new Set([newId, ...results])],
...rest,
}),
}),
getOptimisticResponse: (snap, params, body) => body as any,
}),
delete: base.delete.extend({
getOptimisticResponse: (snap, params) => params,
}),
};
export default ReactionResource;