summaryrefslogtreecommitdiffstats
path: root/web/react/components/post_body_additional_content.jsx
blob: 8189ba2d331775f8a21cb1818958d3ac835c01be (plain)
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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

const PostAttachmentList = require('./post_attachment_list.jsx');

export default class PostBodyAdditionalContent extends React.Component {
    constructor(props) {
        super(props);

        this.getSlackAttachment = this.getSlackAttachment.bind(this);
        this.getComponent = this.getComponent.bind(this);
    }

    componentWillMount() {
        this.setState({type: this.props.post.type, shouldRender: Boolean(this.props.post.type)});
    }

    getSlackAttachment() {
        const attachments = this.props.post.props && this.props.post.props.attachments || [];
        return (
            <PostAttachmentList
                key={'post_body_additional_content' + this.props.post.id}
                attachments={attachments}
            />
        );
    }

    getComponent() {
        switch (this.state.type) {
        case 'slack_attachment':
            return this.getSlackAttachment();
        }
    }

    render() {
        let content = [];

        if (this.state.shouldRender) {
            const component = this.getComponent();

            if (component) {
                content = component;
            }
        }

        return (
            <div>
                {content}
            </div>
        );
    }
}

PostBodyAdditionalContent.propTypes = {
    post: React.PropTypes.object.isRequired
};