summaryrefslogtreecommitdiffstats
path: root/web/react/components/member_list_team.jsx
blob: f1c31131f54f4fcbb876778a65b0ae31cb4fa8ee (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
61
62
63
64
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import MemberListTeamItem from './member_list_team_item.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() {
        const memberList = this.state.users.map((user) => {
            return (
                <MemberListTeamItem
                    key={user.id}
                    user={user}
                />
            );
        });

        return (
            <table className='table more-table member-list-holder'>
                <tbody>
                    {memberList}
                </tbody>
            </table>
        );
    }
}