// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
var UserStore = require('../stores/user_store.jsx');
var MemberListTeam = require('./member_list_team.jsx');
var utils = require('../utils/utils.jsx');
function getStateFromStores() {
var users = UserStore.getProfiles();
var memberList = [];
for (var id in users) {
if (users.hasOwnProperty(id)) {
memberList.push(users[id]);
}
}
memberList.sort(function sort(a, b) {
if (a.username < b.username) {
return -1;
}
if (a.username > b.username) {
return 1;
}
return 0;
});
return {
member_list: memberList
};
}
export default class TeamMembers extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.state = getStateFromStores();
}
componentDidMount() {
UserStore.addChangeListener(this.onChange);
var self = this;
$(ReactDOM.findDOMNode(this.refs.modal)).on('hidden.bs.modal', function show() {
self.setState({render_members: false});
});
$(ReactDOM.findDOMNode(this.refs.modal)).on('show.bs.modal', function hide() {
self.setState({render_members: true});
});
}
componentWillUnmount() {
UserStore.removeChangeListener(this.onChange);
}
onChange() {
var newState = getStateFromStores();
if (!utils.areObjectsEqual(newState, this.state)) {
this.setState(newState);
}
}
render() {
var serverError = null;
if (this.state.server_error) {
serverError = ;
}
var renderMembers = '';
if (this.state.render_members) {
renderMembers =