summaryrefslogtreecommitdiffstats
path: root/webapp/components/emoji_picker/emoji_picker_container.jsx
blob: d352539ab1e55eaf1039e7baebe0991f0fba35bb (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
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import EmojiStore from 'stores/emoji_store.jsx';

import EmojiPicker from './emoji_picker.jsx';

export default class EmojiPickerContainer extends React.Component {
    static propTypes = {
        onEmojiClick: React.PropTypes.func.isRequred
    }

    constructor(props) {
        super(props);
        this.handleEmojiChange = this.handleEmojiChange.bind(this);

        this.state = {
            customEmojis: EmojiStore.getCustomEmojiMap().values() ? EmojiStore.getCustomEmojiMap().values() : []
        };
    }

    componentDidMount() {
        EmojiStore.addChangeListener(this.handleEmojiChange);
    }

    componentWillUnount() {
        EmojiStore.removeChangeListener(this.handleEmojiChange);
    }

    handleEmojiChange() {
        this.setState({
            customEmojis: EmojiStore.getCustomEmojiMap().values()
        });
    }

    render() {
        return (
            <EmojiPicker
                customEmojis={EmojiStore.getCustomEmojiMap().values()}
                onEmojiClick={this.props.onEmojiClick}
            />
        );
    }
}