render messages nicer
This commit is contained in:
parent
5ab5f6fec2
commit
8e50efb3c1
3 changed files with 36 additions and 12 deletions
|
@ -271,7 +271,7 @@
|
||||||
}
|
}
|
||||||
.chat-box .chat-messages {
|
.chat-box .chat-messages {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 16px 0px 0px 0px;
|
padding: 16px 0px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
.chat-box .chat-messages .chat-message .chat-message-user {
|
.chat-box .chat-messages .chat-message .chat-message-user {
|
||||||
width: 15%;
|
width: 12%;
|
||||||
float: left;
|
float: left;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
color: #BBB;
|
color: #BBB;
|
||||||
|
@ -304,20 +304,25 @@
|
||||||
}
|
}
|
||||||
.chat-box .chat-messages .chat-message .chat-message-user img {
|
.chat-box .chat-messages .chat-message .chat-message-user img {
|
||||||
border: 2px solid #424242;
|
border: 2px solid #424242;
|
||||||
width: 32px;
|
width: 26px;
|
||||||
height: 32px;
|
height: 26px;
|
||||||
border-radius: 18px;
|
border-radius: 14px;
|
||||||
|
}
|
||||||
|
.chat-box .chat-messages .chat-message .chat-message-meta {
|
||||||
|
padding: 0 8px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
.chat-box .chat-messages .chat-message .chat-message-username {
|
||||||
|
color: #4fc059;
|
||||||
}
|
}
|
||||||
.chat-box .chat-messages .chat-message .chat-message-text {
|
.chat-box .chat-messages .chat-message .chat-message-text {
|
||||||
width: 73%;
|
width: 80%;
|
||||||
float: left;
|
float: left;
|
||||||
margin-top: 12px;
|
|
||||||
padding: 2px 8px 0;
|
padding: 2px 8px 0;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
.chat-box .chat-messages .chat-message .chat-message-time {
|
.chat-box .chat-messages .chat-message .chat-message-time {
|
||||||
float: right;
|
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
color: #757575;
|
color: #757575;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,18 @@ function formatDate(created_at) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Message = props => {
|
const Message = props => {
|
||||||
const { user_image, user_name, message, created_at } = props
|
const { user_image, user_name, message, created_at, heading } = props
|
||||||
const messageHtml = {__html: linker.link(message)}
|
const messageHtml = {__html: linker.link(message)}
|
||||||
return (
|
return (
|
||||||
<div className="chat-message">
|
<div className="chat-message">
|
||||||
<div className="chat-message-user">
|
<div className="chat-message-user">
|
||||||
<img src={user_image} title={user_name} />
|
{heading && <img src={user_image} />}
|
||||||
</div>
|
</div>
|
||||||
|
{heading && <div className="chat-message-meta">
|
||||||
|
<span className='chat-message-username'>{user_name}</span>
|
||||||
|
<span className='chat-message-time'>{formatDate(created_at)}</span>
|
||||||
|
</div>}
|
||||||
<div className="chat-message-text" dangerouslySetInnerHTML={messageHtml}></div>
|
<div className="chat-message-text" dangerouslySetInnerHTML={messageHtml}></div>
|
||||||
<div className="chat-message-time">{formatDate(created_at)}</div>
|
|
||||||
<div className="clearfloat"></div>
|
<div className="clearfloat"></div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,22 @@ import Unread from './Unread'
|
||||||
import Participant from './Participant'
|
import Participant from './Participant'
|
||||||
import Message from './Message'
|
import Message from './Message'
|
||||||
|
|
||||||
|
function makeList(messages) {
|
||||||
|
let currentHeader
|
||||||
|
return messages ? messages.map(m => {
|
||||||
|
let heading = false
|
||||||
|
if (!currentHeader) {
|
||||||
|
heading = true
|
||||||
|
currentHeader = m
|
||||||
|
} else {
|
||||||
|
// not same user or time diff of greater than 3 minutes
|
||||||
|
heading = m.user_id !== currentHeader.user_id || Math.floor(Math.abs(new Date(currentHeader.created_at) - new Date(m.created_at)) / 60000) > 3
|
||||||
|
currentHeader = heading ? m : currentHeader
|
||||||
|
}
|
||||||
|
return <Message {...m} key={m.id} heading={heading}/>
|
||||||
|
}) : null
|
||||||
|
}
|
||||||
|
|
||||||
class MapChat extends Component {
|
class MapChat extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
@ -125,7 +141,7 @@ class MapChat extends Component {
|
||||||
<Unread count={unreadMessages} />
|
<Unread count={unreadMessages} />
|
||||||
</div>
|
</div>
|
||||||
<div className="chat-messages" ref={div => this.messagesDiv = div}>
|
<div className="chat-messages" ref={div => this.messagesDiv = div}>
|
||||||
{messages.map(message => <Message key={message.id} {...message} />)}
|
{makeList(messages)}
|
||||||
</div>
|
</div>
|
||||||
<textarea className="chat-input"
|
<textarea className="chat-input"
|
||||||
ref={textarea => this.messageInput = textarea}
|
ref={textarea => this.messageInput = textarea}
|
||||||
|
|
Loading…
Reference in a new issue