This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
member_list_channel.jsx
126 lines (103 loc) · 4.27 KB
/
member_list_channel.jsx
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import Constants from 'utils/constants.jsx';
import * as UserAgent from 'utils/user_agent.jsx';
import ChannelMembersDropdown from 'components/channel_members_dropdown';
import SearchableUserList from 'components/searchable_user_list/searchable_user_list_container.jsx';
const USERS_PER_PAGE = 50;
export default class MemberListChannel extends React.PureComponent {
static propTypes = {
currentTeamId: PropTypes.string.isRequired,
currentChannelId: PropTypes.string.isRequired,
searchTerm: PropTypes.string.isRequired,
usersToDisplay: PropTypes.arrayOf(PropTypes.object).isRequired,
actionUserProps: PropTypes.object.isRequired,
totalChannelMembers: PropTypes.number.isRequired,
channel: PropTypes.object.isRequired,
actions: PropTypes.shape({
searchProfiles: PropTypes.func.isRequired,
getChannelStats: PropTypes.func.isRequired,
setModalSearchTerm: PropTypes.func.isRequired,
loadProfilesAndTeamMembersAndChannelMembers: PropTypes.func.isRequired,
loadStatusesForProfilesList: PropTypes.func.isRequired,
loadTeamMembersAndChannelMembersForProfilesList: PropTypes.func.isRequired,
}).isRequired,
}
constructor(props) {
super(props);
this.searchTimeoutId = 0;
this.state = {
loading: true,
};
}
componentDidMount() {
const {
actions,
currentChannelId,
currentTeamId,
} = this.props;
actions.loadProfilesAndTeamMembersAndChannelMembers(0, Constants.PROFILE_CHUNK_SIZE, currentTeamId, currentChannelId).then(({data}) => {
if (data) {
this.loadComplete();
}
});
actions.getChannelStats(currentChannelId);
}
componentWillUnmount() {
this.props.actions.setModalSearchTerm('');
}
UNSAFE_componentWillReceiveProps(nextProps) { // eslint-disable-line camelcase
if (this.props.searchTerm !== nextProps.searchTerm) {
clearTimeout(this.searchTimeoutId);
const searchTerm = nextProps.searchTerm;
if (searchTerm === '') {
this.loadComplete();
this.searchTimeoutId = '';
return;
}
const searchTimeoutId = setTimeout(
async () => {
const {data} = await this.props.actions.searchProfiles(searchTerm, {team_id: nextProps.currentTeamId, in_channel_id: nextProps.currentChannelId});
if (searchTimeoutId !== this.searchTimeoutId) {
return;
}
this.setState({loading: true});
nextProps.actions.loadStatusesForProfilesList(data);
nextProps.actions.loadTeamMembersAndChannelMembersForProfilesList(data, nextProps.currentTeamId, nextProps.currentChannelId).then(({data: membersLoaded}) => {
if (membersLoaded) {
this.loadComplete();
}
});
},
Constants.SEARCH_TIMEOUT_MILLISECONDS
);
this.searchTimeoutId = searchTimeoutId;
}
}
loadComplete = () => {
this.setState({loading: false});
}
nextPage = (page) => {
this.props.actions.loadProfilesAndTeamMembersAndChannelMembers(page + 1, USERS_PER_PAGE);
}
handleSearch = (term) => {
this.props.actions.setModalSearchTerm(term);
}
render() {
const channelIsArchived = this.props.channel.delete_at !== 0;
return (
<SearchableUserList
users={this.props.usersToDisplay}
usersPerPage={USERS_PER_PAGE}
total={this.props.totalChannelMembers}
nextPage={this.nextPage}
search={this.handleSearch}
actions={channelIsArchived ? [] : [ChannelMembersDropdown]}
actionUserProps={this.props.actionUserProps}
focusOnMount={!UserAgent.isMobile()}
/>
);
}
}