summaryrefslogtreecommitdiffstats
path: root/web/react
diff options
context:
space:
mode:
authornickago <ngonella@calpoly.edu>2015-08-04 09:13:19 -0700
committernickago <ngonella@calpoly.edu>2015-08-04 09:13:19 -0700
commitdb0fb95468d890e6f54d32c543161b693481ffcf (patch)
tree7b911f55a7407025e4ff78beae96446683895622 /web/react
parent2c46ee8420eb19d827d3f2072bd536aae2038f84 (diff)
downloadchat-db0fb95468d890e6f54d32c543161b693481ffcf.tar.gz
chat-db0fb95468d890e6f54d32c543161b693481ffcf.tar.bz2
chat-db0fb95468d890e6f54d32c543161b693481ffcf.zip
Added listening to the Team Store and removed current team name from team swap menu
Diffstat (limited to 'web/react')
-rw-r--r--web/react/components/sidebar_header.jsx25
1 files changed, 14 insertions, 11 deletions
diff --git a/web/react/components/sidebar_header.jsx b/web/react/components/sidebar_header.jsx
index e01ddcd05..4cea43688 100644
--- a/web/react/components/sidebar_header.jsx
+++ b/web/react/components/sidebar_header.jsx
@@ -1,15 +1,15 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
-
var utils = require('../utils/utils.jsx');
var client = require('../utils/client.jsx');
var UserStore = require('../stores/user_store.jsx');
+var TeamStore = require('../stores/team_store.jsx');
var Constants = require('../utils/constants.jsx');
function getStateFromStores() {
- return { teams: UserStore.getTeams() };
+ return {teams: UserStore.getTeams(), currentTeam: TeamStore.getCurrent()};
}
var NavbarDropdown = React.createClass({
@@ -19,7 +19,8 @@ var NavbarDropdown = React.createClass({
},
blockToggle: false,
componentDidMount: function() {
- UserStore.addTeamsChangeListener(this._onChange);
+ UserStore.addTeamsChangeListener(this.onListenerChange);
+ TeamStore.addChangeListener(this.onListenerChange);
var self = this;
$(this.refs.dropdown.getDOMNode()).on('hide.bs.dropdown', function(e) {
@@ -28,11 +29,12 @@ var NavbarDropdown = React.createClass({
});
},
componentWillUnmount: function() {
- UserStore.removeTeamsChangeListener(this._onChange);
+ UserStore.removeTeamsChangeListener(this.onListenerChange);
+ TeamStore.removeChangeListener(this.onListenerChange);
$(this.refs.dropdown.getDOMNode()).off('hide.bs.dropdown');
},
- _onChange: function() {
+ onListenerChange: function() {
if (this.isMounted()) {
var newState = getStateFromStores();
if (!utils.areStatesEqual(newState, this.state)) {
@@ -73,12 +75,13 @@ var NavbarDropdown = React.createClass({
var teams = [];
teams.push(<li className="divider" key="div"></li>);
- if (this.state.teams.length > 1) {
- for (var i = 0; i < this.state.teams.length; i++) {
- var teamName = this.state.teams[i];
-
- teams.push(<li key={ teamName }><a href={utils.getWindowLocationOrigin() + "/" + teamName }>Switch to { teamName }</a></li>);
- }
+ if (this.state.teams.length > 1 && this.state.currentTeam) {
+ var curTeamName = this.state.currentTeam.name;
+ this.state.teams.forEach(function(teamName) {
+ if (teamName !== curTeamName) {
+ teams.push(<li key={ teamName }><a href={utils.getWindowLocationOrigin() + "/" + teamName }>Switch to { teamName }</a></li>);
+ }
+ });
}
teams.push(<li><a href={utils.getWindowLocationOrigin() + "/signup_team" }>Create a New Team</a></li>);