-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·100 lines (89 loc) · 2.55 KB
/
main.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
// FeedItem component
function FeedItem(props) {
return (
<article className="feed">
<div className="left">
<div className="img-logo">
<div className="img-logo-wrap">
<img src={props.picture} />
<div className="logo">
<i className="fa fa-twitter"></i>
</div>
</div>
<div className="read-wrap">
<span className="read"></span>
</div>
</div>
</div>
<div className="right">
<div>
<h2>@{props.user}</h2>
<span className="since">{timeSince(props.since)}</span>
</div>
<a href={props.url}>{(props.user_real_name != " " ? props.user_real_name : "Unknown")}</a>
<p>{props.title}</p>
</div>
</article>
)
}
// Feed component
var Feed = React.createClass({
getInitialState: function() {
return {
feeds: []
}
},
componentDidMount: function() {
var _this = this;
$.getJSON('https://web.mention.net/api/accounts/661072_53ca2jsh01c88c4wwkc0wockckk0w4440o4o0w8wkkgco4o888/alerts/1214654/mentions?access_token=ZDdmNDVmYzU1NWZkMDkwMDc4YjBjMzYyZDk2MDI3NGVlNmFmNTJkZDU5MzBhYWRiZGZmNzAxOGM1NDkzNDYxYQ')
.then(function(data){
console.log(data);
_this.setState({
feeds: data.mentions
});
});
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
return (
<section id="feed">
{this.state.feeds.map(function(feed) {
return (
<FeedItem key={feed.id} title={feed.title} user={feed.source_name} user_real_name={feed.twitter_real_name} read={feed.read} picture={feed.picture_url} since={feed.created_at} url={feed.original_url} />
);
})}
</section>
)
}
});
ReactDOM.render(
<Feed />,
document.getElementById('container')
);
// Get Time since feed as been created
function timeSince(date) {
var seconds = Math.floor((new Date() - Date.parse(date)) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + "y";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + "m";
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + "d";
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return interval + "h";
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + "m";
}
return Math.floor(seconds) + " seconds";
}