aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/PM.js
blob: 61e28e9a13c30476378e161793de3d1d63882273 (plain) (blame)
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
import React from 'react';

import { UserType, MessageType } from './Types';

import Avatar from './Avatar';
import { format } from '../utils/embed';

export default function PM(props) {
    const { chat } = props;
    return (
        <li>
            <div style={chatItemStyle(props.visitor, chat)}>
                <Avatar user={chat.user} />
                <div style={bubbleStyle(props.visitor, chat)}>
                    <p dangerouslySetInnerHTML={{ __html: format(chat.body) }} />
                </div>
            </div>
        </li>
    );
}

function bubbleStyle(me, msg) {
    const isMe = me.uid === msg.user.uid;
    const color = isMe ? '#fff' : '#222';
    const background = isMe ? '#0076ff' : '#eee';
    return {
        background: background,
        color: color,
        padding: '0 12px'
    };
}

function chatItemStyle(me, msg) {
    const isMe = me.uid === msg.user.uid;
    const alignment = isMe ? 'flex-end' : 'flex-start';
    return {
        padding: '3px 6px',
        listStyle: 'none',
        margin: '10px 0',
        display: 'flex',
        flexDirection: 'column',
        alignItems: alignment
    };
}

PM.propTypes = {
    chat: MessageType.isRequired,
    visitor: UserType.isRequired
}