-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathStoryLikeButton.tsx
More file actions
76 lines (70 loc) · 1.59 KB
/
Copy pathStoryLikeButton.tsx
File metadata and controls
76 lines (70 loc) · 1.59 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 { useFragment } from "react-relay";
import { graphql } from "relay-runtime";
import type { StoryLikeButtonFragment$key } from "./__generated__/StoryLikeButtonFragment.graphql";
type Props = {
story: StoryLikeButtonFragment$key;
};
const StoryLikeButtonFragment = graphql`
fragment StoryLikeButtonFragment on Story {
id
likeCount
doesViewerLike
}
`;
export default function StoryLikeButton({ story }: Props) {
const data = useFragment<StoryLikeButtonFragment$key>(
StoryLikeButtonFragment,
story
);
const onLikeButtonClicked = () => {
// To be filled in
};
return (
<div className="likeButton">
<LikeCount count={data.likeCount} />
<LikeButton
doesViewerLike={data.doesViewerLike}
onClick={onLikeButtonClicked}
/>
</div>
);
}
function LikeCount({ count }: { count: number }) {
return <div className="likeButton__count">{count} likes</div>;
}
function LikeButton({
doesViewerLike,
onClick,
disabled,
}: {
doesViewerLike: boolean;
onClick: () => void;
disabled?: boolean;
}) {
return (
<button
className="likeButton__button"
onClick={onClick}
disabled={disabled}
>
<span
className={
doesViewerLike
? "likeButton__thumb__viewerLikes"
: "likeButton__thumb__viewerDoesNotLike"
}
>
👍
</span>{" "}
<span
className={
doesViewerLike
? "likeButton__label__viewerLikes"
: "likeButton__label__viewerDoesNotLike"
}
>
Like
</span>
</button>
);
}