dispatch/client/src/js/components/MessageHeader.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-12-28 23:34:32 +00:00
import React, { Component } from 'react';
import Autolinker from 'autolinker';
import { timestamp } from '../util';
export default class MessageHeader extends Component {
shouldComponentUpdate(nextProps) {
return nextProps.message.lines[0] !== this.props.message.lines[0];
}
handleSenderClick = () => {
const { message, openPrivateChat, select } = this.props;
openPrivateChat(message.server, message.from);
select(message.server, message.from, true);
};
2015-12-28 23:34:32 +00:00
render() {
const { message } = this.props;
const line = Autolinker.link(message.lines[0], { stripPrefix: false });
2016-01-05 18:29:22 +00:00
const classes = ['message'];
2015-12-28 23:34:32 +00:00
let sender = null;
2016-01-05 18:29:22 +00:00
if (message.type) {
classes.push(`message-${message.type}`);
}
2015-12-28 23:34:32 +00:00
if (message.from) {
sender = (
<span>
{' '}
<span className="message-sender" onClick={this.handleSenderClick}>
{message.from}
</span>
</span>
);
}
return (
2016-01-05 18:29:22 +00:00
<p className={classes.join(' ')}>
2015-12-28 23:34:32 +00:00
<span className="message-time">{timestamp(message.time)}</span>
{sender}
<span dangerouslySetInnerHTML={{ __html: ' ' + line }}></span>
</p>
);
}
}