summaryrefslogtreecommitdiffstats
path: root/web/react
diff options
context:
space:
mode:
authornickago <ngonella@calpoly.edu>2015-08-20 08:16:17 -0700
committernickago <ngonella@calpoly.edu>2015-08-20 08:16:17 -0700
commit6bab566b8562336f00c977edc59338f1fd86dbda (patch)
tree27e64642a52524d6365dfcb7749d77fff463edd9 /web/react
parent89c39b55db4ff39250b2c79b76cb1ad975303de2 (diff)
downloadchat-6bab566b8562336f00c977edc59338f1fd86dbda.tar.gz
chat-6bab566b8562336f00c977edc59338f1fd86dbda.tar.bz2
chat-6bab566b8562336f00c977edc59338f1fd86dbda.zip
Made state getter member function and fixed scu edge case
Diffstat (limited to 'web/react')
-rw-r--r--web/react/components/channel_invite_modal.jsx74
1 files changed, 35 insertions, 39 deletions
diff --git a/web/react/components/channel_invite_modal.jsx b/web/react/components/channel_invite_modal.jsx
index 7c474c2b4..d90522e8c 100644
--- a/web/react/components/channel_invite_modal.jsx
+++ b/web/react/components/channel_invite_modal.jsx
@@ -9,38 +9,6 @@ var utils = require('../utils/utils.jsx');
var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
-function getStateFromStores() {
- function getId(user) {
- return user.id;
- }
- var users = UserStore.getActiveOnlyProfiles();
- var memberIds = ChannelStore.getCurrentExtraInfo().members.map(getId);
-
- var loading = $.isEmptyObject(users);
-
- var nonmembers = [];
- for (var id in users) {
- if (memberIds.indexOf(id) === -1) {
- nonmembers.push(users[id]);
- }
- }
-
- nonmembers.sort(function sortByUsername(a, b) {
- return a.username.localeCompare(b.username);
- });
-
- var channelName = '';
- if (ChannelStore.getCurrent()) {
- channelName = ChannelStore.getCurrent().display_name;
- }
-
- return {
- nonmembers: nonmembers,
- memberIds: memberIds,
- channelName: channelName,
- loading: loading
- };
-}
export default class ChannelInviteModal extends React.Component {
constructor() {
@@ -48,14 +16,45 @@ export default class ChannelInviteModal extends React.Component {
this.componentDidMount = this.componentDidMount.bind(this);
this.componentWillUnmount = this.componentWillUnmount.bind(this);
- this.shouldComponentUpdate = this.shouldComponentUpdate.bind(this);
this.onShow = this.onShow.bind(this);
this.onHide = this.onHide.bind(this);
this.onListenerChange = this.onListenerChange.bind(this);
this.handleInvite = this.handleInvite.bind(this);
this.isShown = false;
- this.state = getStateFromStores();
+ this.state = this.getStateFromStores();
+ }
+ getStateFromStores() {
+ function getId(user) {
+ return user.id;
+ }
+ var users = UserStore.getActiveOnlyProfiles();
+ var memberIds = ChannelStore.getCurrentExtraInfo().members.map(getId);
+
+ var loading = $.isEmptyObject(users);
+
+ var nonmembers = [];
+ for (var id in users) {
+ if (memberIds.indexOf(id) === -1) {
+ nonmembers.push(users[id]);
+ }
+ }
+
+ nonmembers.sort(function sortByUsername(a, b) {
+ return a.username.localeCompare(b.username);
+ });
+
+ var channelName = '';
+ if (ChannelStore.getCurrent()) {
+ channelName = ChannelStore.getCurrent().display_name;
+ }
+
+ return {
+ nonmembers: nonmembers,
+ memberIds: memberIds,
+ channelName: channelName,
+ loading: loading
+ };
}
componentDidMount() {
$(React.findDOMNode(this)).on('hidden.bs.modal', this.onHide);
@@ -70,9 +69,6 @@ export default class ChannelInviteModal extends React.Component {
ChannelStore.removeChangeListener(this.onListenerChange);
UserStore.removeChangeListener(this.onListenerChange);
}
- shouldComponentUpdate() {
- return this.isShown;
- }
onShow() {
this.isShown = true;
this.onListenerChange();
@@ -81,8 +77,8 @@ export default class ChannelInviteModal extends React.Component {
this.isShown = false;
}
onListenerChange() {
- var newState = getStateFromStores();
- if (!utils.areStatesEqual(this.state, newState)) {
+ var newState = this.getStateFromStores();
+ if (!utils.areStatesEqual(this.state, newState) && this.isShown) {
this.setState(newState);
}
}