summaryrefslogtreecommitdiffstats
path: root/web/react/components/member_list_team.jsx
blob: cfd5359b79e6f7018f89be02f39c9d86dc27c7a1 (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
57
58
59
60
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import FilteredUserList from './filtered_user_list.jsx';
import TeamMembersDropdown from './team_members_dropdown.jsx';
import UserStore from '../stores/user_store.jsx';

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

        this.getUsers = this.getUsers.bind(this);
        this.onChange = this.onChange.bind(this);

        this.state = {
            users: this.getUsers()
        };
    }

    componentDidMount() {
        UserStore.addChangeListener(this.onChange);
    }

    componentWillUnmount() {
        UserStore.removeChangeListener(this.onChange);
    }

    getUsers() {
        const profiles = UserStore.getProfiles();
        const users = [];

        for (const id of Object.keys(profiles)) {
            users.push(profiles[id]);
        }

        users.sort((a, b) => a.username.localeCompare(b.username));

        return users;
    }

    onChange() {
        this.setState({
            users: this.getUsers()
        });
    }

    render() {
        return (
            <FilteredUserList
                style={this.props.style}
                users={this.state.users}
                actions={[TeamMembersDropdown]}
            />
        );
    }
}

MemberListTeam.propTypes = {
    style: React.PropTypes.object
};