-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviews.js
More file actions
38 lines (32 loc) · 995 Bytes
/
views.js
File metadata and controls
38 lines (32 loc) · 995 Bytes
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
import React from 'react';
import moment from 'moment';
import marked from 'marked';
class Post extends React.Component {
constructor(props, context) {
super(props, context);
this.rawMarkup = this.rawMarkup.bind(this);
}
rawMarkup() {
let rawMarkup = marked(this.props.data.data, {sanitize: true});
return { __html: rawMarkup };
}
render() {
var post = this.props.data;
return <div className="post">
<h2><a href={'/' + this.props.username + '/' + post.id}>{post.title}</a></h2>
<span dangerouslySetInnerHTML={this.rawMarkup()} />
<div className="time">{moment(post.updated).format('LLLL')}</div>
</div>;
}
}
class User extends React.Component {
render() {
return <div>
<h1><a href={'/' + this.props.username}>{this.props.username}</a></h1>
<div className="posts">
{this.props.posts.map(d => <Post username={this.props.username} data={d} key={d.id} />)}
</div>
</div>;
}
}
export default User;