-
Notifications
You must be signed in to change notification settings - Fork 66
/
StoryListItem.re
executable file
·74 lines (70 loc) · 2.17 KB
/
StoryListItem.re
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
open Utils;
requireCSS("src/StoryListItem.css");
let commentIcon = requireAssetURI("src/comment.png");
[@react.component]
let make = (~story: StoryData.story, ~index: int, ()) => {
let renderIndex = () =>
<aside className="StoryListItem_storyIndex">
{React.string(string_of_int(index + 1))}
</aside>;
let renderTitle = () => {
let content = React.string(story.title);
<header className="StoryListItem_storyTitle">
{switch (story.url) {
| Some(url) =>
<a href=url className="StoryListItem_link" target="_blank">
content
</a>
| None =>
<Link
href={"/comments/" ++ string_of_int(story.id)}
className="StoryListItem_link">
content
</Link>
}}
</header>;
};
let renderByline = () =>
<div className="StoryListItem_row StoryListItem_byline">
/* TODO: badge */
<span className="StoryListItem_number">
<b> {React.string(string_of_int(story.score))} </b>
{React.string(" points")}
</span>
<span className="StoryListItem_storyTime">
{let time = story.time
let by = story.by
React.string({j| submitted $time by $by|j})}
</span>
</div>;
let renderArticleButton = () =>
<div className="StoryListItem_flexRow">
{renderIndex()}
<div className="StoryListItem_storyCell">
{renderTitle()}
{renderByline()}
</div>
</div>;
let renderCommentsButton = () =>
<div className="StoryListItem_commentsCell">
<Link
href={"/comments/" ++ string_of_int(story.id)}
className="StoryListItem_link">
<div>
<img alt="comments" className="StoryListItem_icon" src=commentIcon />
</div>
<div>
<span className="StoryListItem_commentsText">
<span className="StoryListItem_number">
{React.string(string_of_int(story.descendants))}
</span>
{React.string(" comments")}
</span>
</div>
</Link>
</div>;
<div className="StoryListItem_itemRow">
{renderArticleButton()}
{renderCommentsButton()}
</div>;
};