-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFeedsList.jsx
87 lines (76 loc) · 2.39 KB
/
FeedsList.jsx
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
81
82
83
84
85
86
87
/* eslint-disable react/forbid-prop-types */
import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
const FeedList = ({ feeds }) => (
<div className="list-group">
{feeds !== null
&& feeds.map((feed) => {
let timeSince = null;
let commitMsg = '';
let avatarUrl = null;
let loginName = null;
let repoUrl = null;
if (feed.created_at) {
timeSince = moment(new Date(feed.created_at)).fromNow();
} else {
timeSince = '';
}
if (feed.payload) {
const commitObj = feed.payload.commits;
if (commitObj !== undefined && commitObj[0] !== undefined) {
commitMsg = commitObj[0].message;
}
} else {
commitMsg = '';
}
if (feed.actor !== undefined && feed.actor.avatar_url) {
avatarUrl = feed.actor.avatar_url;
} else {
avatarUrl = null;
}
if (feed.repo && feed.repo.name) {
repoUrl = `http://github.com/${feed.repo.name}`;
loginName = feed.repo.name;
} else {
loginName = null;
}
return (
<a
id={feed.id}
key={feed.id}
href={repoUrl}
/* eslint-disable-next-line react/jsx-no-target-blank */
target="_blank"
className="list-group-item list-group-item-action flex-column align-items-start"
>
<div className="d-flex w-100 justify-content-between">
<div className="flex-10">
{avatarUrl && <img src={avatarUrl} alt={feed.actor.login} width="90" />}
</div>
<div className="flex-90">
<h6 className="mb-1 feed-title">
{feed.type}
{' '}
→
{' '}
{loginName}
</h6>
<small style={{ float: 'right' }}>{timeSince}</small>
<br />
<p className="mb-1">{commitMsg}</p>
</div>
</div>
</a>
);
})
}
</div>
);
FeedList.defaultProps = {
feeds: [],
};
FeedList.propTypes = {
feeds: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
};
export default FeedList;