From e2a24f40b750886156cef33a38218315c06aef35 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Mon, 31 Aug 2015 09:35:31 -0700 Subject: Cosmetic reformatting of multiple jsx files --- web/react/components/navbar_dropdown.jsx | 210 +++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 web/react/components/navbar_dropdown.jsx (limited to 'web/react/components/navbar_dropdown.jsx') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx new file mode 100644 index 000000000..7ffaeb712 --- /dev/null +++ b/web/react/components/navbar_dropdown.jsx @@ -0,0 +1,210 @@ +// 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(), currentTeam: TeamStore.getCurrent()}; +} + +export default class NavbarDropdown extends React.Component { + constructor(props) { + super(props); + this.blockToggle = false; + + this.handleLogoutClick = this.handleLogoutClick.bind(this); + this.onListenerChange = this.onListenerChange.bind(this); + + this.state = getStateFromStores(); + } + handleLogoutClick(e) { + e.preventDefault(); + client.logout(); + } + componentDidMount() { + UserStore.addTeamsChangeListener(this.onListenerChange); + TeamStore.addChangeListener(this.onListenerChange); + + var self = this; + $(this.refs.dropdown.getDOMNode()).on('hide.bs.dropdown', function resetDropdown() { + self.blockToggle = true; + setTimeout(function blockTimeout() { + self.blockToggle = false; + }, 100); + }); + } + componentWillUnmount() { + UserStore.removeTeamsChangeListener(this.onListenerChange); + TeamStore.removeChangeListener(this.onListenerChange); + + $(this.refs.dropdown.getDOMNode()).off('hide.bs.dropdown'); + } + onListenerChange() { + var newState = getStateFromStores(); + if (!Utils.areStatesEqual(newState, this.state)) { + this.setState(newState); + } + } + render() { + var teamLink = ''; + var inviteLink = ''; + var manageLink = ''; + var currentUser = UserStore.getCurrentUser(); + var isAdmin = false; + var teamSettings = null; + + if (currentUser != null) { + isAdmin = currentUser.roles.indexOf('admin') > -1; + + inviteLink = (
  • + + Invite New Member + +
  • ); + + if (this.props.teamType === 'O') { + teamLink = ( +
  • + + Manage Team + +
  • ); + teamSettings = (
  • + + Team Settings + +
  • ); + } + + var teams = []; + + teams.push(
  • +
  • ); + if (this.state.teams.length > 1 && this.state.currentTeam) { + var curTeamName = this.state.currentTeam.name; + this.state.teams.forEach(function listTeams(teamName) { + if (teamName !== curTeamName) { + teams.push(
  • Switch to {teamName}
  • ); + } + }); + } + teams.push(
  • + + Create a New Team + +
  • ); + + return ( + + ); + } +} + +NavbarDropdown.defaultProps = { + teamType: '' +}; +NavbarDropdown.propTypes = { + teamType: React.PropTypes.string +}; -- cgit v1.2.3-1-g7c22 From aac83dcedc644dfc23fc46366e54c65e0c86c5b9 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Wed, 2 Sep 2015 09:46:40 -0700 Subject: Additional refactoring according to issues not caught by eslint --- web/react/components/navbar_dropdown.jsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'web/react/components/navbar_dropdown.jsx') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index 7ffaeb712..e818a5c92 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -30,19 +30,18 @@ export default class NavbarDropdown extends React.Component { UserStore.addTeamsChangeListener(this.onListenerChange); TeamStore.addChangeListener(this.onListenerChange); - var self = this; - $(this.refs.dropdown.getDOMNode()).on('hide.bs.dropdown', function resetDropdown() { - self.blockToggle = true; + $(React.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', function resetDropdown() { + this.blockToggle = true; setTimeout(function blockTimeout() { - self.blockToggle = false; - }, 100); - }); + this.blockToggle = false; + }.bind(this), 100); + }.bind(this)); } componentWillUnmount() { UserStore.removeTeamsChangeListener(this.onListenerChange); TeamStore.removeChangeListener(this.onListenerChange); - $(this.refs.dropdown.getDOMNode()).off('hide.bs.dropdown'); + $(React.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); } onListenerChange() { var newState = getStateFromStores(); -- cgit v1.2.3-1-g7c22