-
Notifications
You must be signed in to change notification settings - Fork 43
/
ArticleInfo.js
54 lines (52 loc) · 1.25 KB
/
ArticleInfo.js
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
import gql from 'graphql-tag';
import { ngettext, msgid } from 'ttag';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import isValid from 'date-fns/isValid';
import format from 'date-fns/format';
export default function ArticleInfo({ article }) {
const createdAt = new Date(article.createdAt);
const { replyRequestCount, replyCount } = article;
return (
<div className="root">
{ngettext(
msgid`${replyRequestCount} occurence`,
`${replyRequestCount} occurences`,
replyRequestCount
)}
{article.replyCount > 0 ? (
<span>
・
{ngettext(
msgid`${replyCount} response`,
`${replyCount} responses`,
replyCount
)}
</span>
) : (
''
)}
{isValid(createdAt) ? (
<span title={format(createdAt, 'Pp')}>
・{formatDistanceToNow(createdAt)}
</span>
) : (
''
)}
<style jsx>{`
.root {
font-size: var(--font-size);
color: rgba(0, 0, 0, 0.5);
}
`}</style>
</div>
);
}
ArticleInfo.fragments = {
articleInfo: gql`
fragment ArticleInfo on Article {
replyRequestCount
replyCount
createdAt
}
`,
};