forked from benmvp/react-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailView.js
More file actions
61 lines (51 loc) · 1.67 KB
/
Copy pathEmailView.js
File metadata and controls
61 lines (51 loc) · 1.67 KB
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
import React from 'react';
import {EMAIL_PROP_TYPE} from './constants';
export default class EmailView extends React.Component {
static propTypes = {
email: EMAIL_PROP_TYPE.isRequired,
onClose: React.PropTypes.func.isRequired,
onDelete: React.PropTypes.func.isRequired,
onMarkUnread: React.PropTypes.func,
onMarkRead: React.PropTypes.func
}
_handleClose(e) {
e.stopPropagation();
this.props.onClose();
}
_handleDelete(e) {
e.stopPropagation();
this.props.onDelete();
}
_handleMarkUnread(e) {
e.stopPropagation();
if (this.props.onMarkUnread) {
this.props.onMarkUnread();
}
}
_handleMarkRead(e) {
e.stopPropagation();
if (this.props.onMarkRead) {
this.props.onMarkRead();
}
}
render() {
let {
email: {subject, from, date, message, unread}
} = this.props;
let rawMessage = {__html: message};
let markUnreadReadButton = unread
? (<button onClick={this._handleMarkRead.bind(this)}>Mark Read</button>)
: (<button onClick={this._handleMarkUnread.bind(this)}>Mark Unread</button>);
return (
<div>
<h1>{subject}</h1>
<h2>From: <a href={`mailto:${from}`}>{from}</a></h2>
<h3>{date}</h3>
<div dangerouslySetInnerHTML={rawMessage} />
{markUnreadReadButton}
<button onClick={this._handleDelete.bind(this)}>Delete</button>
<button onClick={this._handleClose.bind(this)}>Close</button>
</div>
);
}
}