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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import SearchableUserList from 'components/searchable_user_list.jsx';
import TeamMembersDropdown from 'components/team_members_dropdown.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import {searchUsers, loadProfilesAndTeamMembers, loadTeamMembersForProfilesList} from 'actions/user_actions.jsx';
import {getTeamStats} from 'utils/async_client.jsx';
import Constants from 'utils/constants.jsx';
import React from 'react';
const USERS_PER_PAGE = 50;
export default class MemberListTeam extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onStatsChange = this.onStatsChange.bind(this);
this.search = this.search.bind(this);
this.loadComplete = this.loadComplete.bind(this);
const stats = TeamStore.getCurrentStats();
this.state = {
users: UserStore.getProfileListInTeam(),
teamMembers: Object.assign([], TeamStore.getMembersInTeam()),
total: stats.member_count,
search: false,
loading: true
};
}
componentDidMount() {
UserStore.addInTeamChangeListener(this.onChange);
TeamStore.addChangeListener(this.onChange);
TeamStore.addStatsChangeListener(this.onStatsChange);
loadProfilesAndTeamMembers(0, Constants.PROFILE_CHUNK_SIZE, TeamStore.getCurrentId(), this.loadComplete);
getTeamStats(TeamStore.getCurrentId());
}
componentWillUnmount() {
UserStore.removeInTeamChangeListener(this.onChange);
TeamStore.removeChangeListener(this.onChange);
TeamStore.removeStatsChangeListener(this.onStatsChange);
}
loadComplete() {
this.setState({loading: false});
}
onChange() {
if (!this.state.search) {
this.setState({users: UserStore.getProfileListInTeam()});
}
this.setState({teamMembers: Object.assign([], TeamStore.getMembersInTeam())});
}
onStatsChange() {
const stats = TeamStore.getCurrentStats();
this.setState({total: stats.member_count});
}
nextPage(page) {
loadProfilesAndTeamMembers((page + 1) * USERS_PER_PAGE, USERS_PER_PAGE);
}
search(term) {
if (term === '') {
this.setState({search: false, users: UserStore.getProfileListInTeam()});
return;
}
searchUsers(
term,
TeamStore.getCurrentId(),
{},
(users) => {
this.setState({loading: true, search: true, users});
loadTeamMembersForProfilesList(users, TeamStore.getCurrentId(), this.loadComplete);
}
);
}
render() {
let teamMembersDropdown = null;
if (this.props.isAdmin) {
teamMembersDropdown = [TeamMembersDropdown];
}
const teamMembers = this.state.teamMembers;
const users = this.state.users;
const actionUserProps = {};
let usersToDisplay;
if (this.state.loading) {
usersToDisplay = null;
} else {
usersToDisplay = [];
for (let i = 0; i < users.length; i++) {
const user = users[i];
if (teamMembers[user.id]) {
usersToDisplay.push(user);
actionUserProps[user.id] = {
teamMember: teamMembers[user.id]
};
}
}
}
return (
<SearchableUserList
style={this.props.style}
users={usersToDisplay}
usersPerPage={USERS_PER_PAGE}
total={this.state.total}
nextPage={this.nextPage}
search={this.search}
actions={teamMembersDropdown}
actionUserProps={actionUserProps}
/>
);
}
}
MemberListTeam.propTypes = {
style: React.PropTypes.object,
isAdmin: React.PropTypes.bool
};
|