blob: 338d95fa06a91ceeb1e9af19ba9f4fae281cc8b5 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import IntegrationStore from 'stores/integration_store.jsx';
import UserStore from 'stores/user_store.jsx';
import {loadTeamCommands} from 'actions/integration_actions.jsx';
import PropTypes from 'prop-types';
import React from 'react';
export default class CommandsContainer extends React.Component {
static get propTypes() {
return {
team: PropTypes.object,
user: PropTypes.object,
children: PropTypes.node.isRequired,
isAdmin: PropTypes.bool
};
}
constructor(props) {
super(props);
this.handleIntegrationChange = this.handleIntegrationChange.bind(this);
this.handleUserChange = this.handleUserChange.bind(this);
const teamId = this.props.team ? this.props.team.id : '';
this.state = {
commands: IntegrationStore.getCommands(teamId) || [],
loading: !IntegrationStore.hasReceivedCommands(teamId),
users: UserStore.getProfiles()
};
}
componentDidMount() {
IntegrationStore.addChangeListener(this.handleIntegrationChange);
UserStore.addChangeListener(this.handleUserChange);
if (window.mm_config.EnableCommands === 'true') {
loadTeamCommands((() => this.setState({loading: false})));
}
}
componentWillUnmount() {
IntegrationStore.removeChangeListener(this.handleIntegrationChange);
UserStore.removeChangeListener(this.handleUserChange);
}
handleIntegrationChange() {
const teamId = this.props.team.id;
this.setState({
commands: IntegrationStore.getCommands(teamId)
});
}
handleUserChange() {
this.setState({users: UserStore.getProfiles()});
}
render() {
return (
<div>
{React.cloneElement(this.props.children, {
commands: this.state.commands,
users: this.state.users,
loading: this.state.loading,
team: this.props.team,
user: this.props.user,
isAdmin: this.props.isAdmin
})}
</div>
);
}
}
|