From 2b80620cee554560ef5f6eb078c2c5f5d0532326 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 14 Aug 2015 17:12:02 -0700 Subject: Private message channels no longer refresh on creation/first use --- web/react/components/sidebar.jsx | 46 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/sidebar.jsx b/web/react/components/sidebar.jsx index 6735bd6e5..59e93d7e6 100644 --- a/web/react/components/sidebar.jsx +++ b/web/react/components/sidebar.jsx @@ -3,6 +3,7 @@ var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); var ChannelStore = require('../stores/channel_store.jsx'); +var Client = require('../utils/client.jsx'); var AsyncClient = require('../utils/async_client.jsx'); var SocketStore = require('../stores/socket_store.jsx'); var UserStore = require('../stores/user_store.jsx'); @@ -70,6 +71,7 @@ function getStateFromStores() { tempChannel.status = UserStore.getStatus(teammate.id); tempChannel.last_post_at = 0; tempChannel.total_msg_count = 0; + tempChannel.type = 'D'; readDirectChannels.push(tempChannel); } } @@ -282,7 +284,10 @@ module.exports = React.createClass({ } }, getInitialState: function() { - return getStateFromStores(); + var newState = getStateFromStores(); + newState.loadingPMChannel = -1; + + return newState; }, render: function() { var members = this.state.members; @@ -294,7 +299,7 @@ module.exports = React.createClass({ this.firstUnreadChannel = null; this.lastUnreadChannel = null; - function createChannelElement(channel) { + function createChannelElement(channel, index) { var channelMember = members[channel.id]; var linkClass = ''; @@ -345,21 +350,50 @@ module.exports = React.createClass({ } else { statusIcon = Constants.OFFLINE_ICON_SVG; } - status = ; + + if (self.state.loadingPMChannel === index) { + status = ; + } else { + status = ; + } } // set up click handler to switch channels (or create a new channel for non-existant ones) var clickHandler = null; var href = '#'; var teamURL = TeamStore.getCurrentTeamUrl(); + if (!channel.fake) { clickHandler = function(e) { e.preventDefault(); utils.switchChannel(channel); }; - } - if (channel.fake && teamURL){ - href = teamURL + '/channels/' + channel.name; + } else if (channel.fake && teamURL) { + // It's a direct message channel that doesn't exist yet so let's create it + var ids = channel.name.split('__'); + var otherUserId = ''; + if (ids[0] === UserStore.getCurrentId()) { + otherUserId = ids[1]; + } else { + otherUserId = ids[0]; + } + + clickHandler = function(e) { + e.preventDefault(); + self.setState({loadingPMChannel: index}); + + Client.createPMChannelIfNotExists(channel, otherUserId, + function(data) { + self.setState({loadingPMChannel: -1}); + AsyncClient.getChannel(data.id); + utils.switchChannel(data); + }, + function() { + self.setState({loadingPMChannel: -1}); + window.location.href = teamURL + '/channels/' + channel.name; + } + ); + }; } return ( -- cgit v1.2.3-1-g7c22 From e149bc6212218dd8a3d6e108eb112b15dcdb42bd Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 14 Aug 2015 17:39:50 -0700 Subject: Cosmetic reformatting of sidebar.jsx --- web/react/components/sidebar.jsx | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/sidebar.jsx b/web/react/components/sidebar.jsx index 59e93d7e6..6883cd4f0 100644 --- a/web/react/components/sidebar.jsx +++ b/web/react/components/sidebar.jsx @@ -1,7 +1,6 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. -var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); var ChannelStore = require('../stores/channel_store.jsx'); var Client = require('../utils/client.jsx'); var AsyncClient = require('../utils/async_client.jsx'); @@ -12,9 +11,7 @@ var BrowserStore = require('../stores/browser_store.jsx'); var utils = require('../utils/utils.jsx'); var SidebarHeader = require('./sidebar_header.jsx'); var SearchBox = require('./search_bar.jsx'); - var Constants = require('../utils/constants.jsx'); -var ActionTypes = Constants.ActionTypes; function getStateFromStores() { var members = ChannelStore.getAllMembers(); @@ -78,7 +75,7 @@ function getStateFromStores() { // If we don't have MAX_DMS unread channels, sort the read list by last_post_at if (showDirectChannels.length < Constants.MAX_DMS) { - readDirectChannels.sort(function(a, b) { + readDirectChannels.sort(function sortByLastPost(a, b) { // sort by last_post_at first if (a.last_post_at > b.last_post_at) { return -1; @@ -126,6 +123,10 @@ function getStateFromStores() { module.exports = React.createClass({ displayName: 'Sidebar', + propTypes: { + teamType: React.PropTypes.string, + teamDisplayName: React.PropTypes.string + }, componentDidMount: function() { ChannelStore.addChangeListener(this.onChange); UserStore.addChangeListener(this.onChange); @@ -246,17 +247,17 @@ module.exports = React.createClass({ var channel = ChannelStore.getCurrent(); if (channel) { if (channel.type === 'D') { - var teammate_username = utils.getDirectTeammate(channel.id).username; - document.title = teammate_username + ' ' + document.title.substring(document.title.lastIndexOf('-')); + var teammateUsername = utils.getDirectTeammate(channel.id).username; + document.title = teammateUsername + ' ' + document.title.substring(document.title.lastIndexOf('-')); } else { document.title = channel.display_name + ' ' + document.title.substring(document.title.lastIndexOf('-')); } } }, - onScroll: function(e) { + onScroll: function() { this.updateUnreadIndicators(); }, - onResize: function(e) { + onResize: function() { this.updateUnreadIndicators(); }, updateUnreadIndicators: function() { @@ -301,6 +302,7 @@ module.exports = React.createClass({ function createChannelElement(channel, index) { var channelMember = members[channel.id]; + var msgCount; var linkClass = ''; if (channel.id === activeId) { @@ -309,7 +311,7 @@ module.exports = React.createClass({ var unread = false; if (channelMember) { - var msgCount = channel.total_msg_count - channelMember.msg_count; + msgCount = channel.total_msg_count - channelMember.msg_count; unread = (msgCount > 0 && channelMember.notify_level !== 'quiet') || channelMember.mention_count > 0; } @@ -327,7 +329,7 @@ module.exports = React.createClass({ if (channelMember) { if (channel.type === 'D') { // direct message channels show badges for any number of unread posts - var msgCount = channel.total_msg_count - channelMember.msg_count; + msgCount = channel.total_msg_count - channelMember.msg_count; if (msgCount > 0) { badge = {msgCount}; badgesActive = true; @@ -359,12 +361,12 @@ module.exports = React.createClass({ } // set up click handler to switch channels (or create a new channel for non-existant ones) - var clickHandler = null; + var handleClick = null; var href = '#'; var teamURL = TeamStore.getCurrentTeamUrl(); if (!channel.fake) { - clickHandler = function(e) { + handleClick = function clickHandler(e) { e.preventDefault(); utils.switchChannel(channel); }; @@ -378,17 +380,17 @@ module.exports = React.createClass({ otherUserId = ids[0]; } - clickHandler = function(e) { + handleClick = function clickHandler(e) { e.preventDefault(); self.setState({loadingPMChannel: index}); Client.createPMChannelIfNotExists(channel, otherUserId, - function(data) { + function success(data) { self.setState({loadingPMChannel: -1}); AsyncClient.getChannel(data.id); utils.switchChannel(data); }, - function() { + function error() { self.setState({loadingPMChannel: -1}); window.location.href = teamURL + '/channels/' + channel.name; } @@ -398,24 +400,24 @@ module.exports = React.createClass({ return (
  • - + {status} {channel.display_name} {badge}
  • ); - }; + } // create elements for all 3 types of channels var channelItems = this.state.channels.filter( - function(channel) { + function filterPublicChannels(channel) { return channel.type === 'O'; } ).map(createChannelElement); var privateChannelItems = this.state.channels.filter( - function(channel) { + function filterPrivateChannels(channel) { return channel.type === 'P'; } ).map(createChannelElement); @@ -444,7 +446,7 @@ module.exports = React.createClass({ directMessageMore = (
  • - {'More ('+this.state.hideDirectChannels.length+')'} + {'More (' + this.state.hideDirectChannels.length + ')'}
  • ); -- cgit v1.2.3-1-g7c22 From 56eeb2f6efd04a8ff7b9f6aec18cda5089db1b28 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 14 Aug 2015 17:55:30 -0700 Subject: Prepatory cosmetic refactoring of more_direct_channels.jsx --- web/react/components/more_direct_channels.jsx | 66 +++++++++++++++------------ 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx index 901cd228f..65bf2d988 100644 --- a/web/react/components/more_direct_channels.jsx +++ b/web/react/components/more_direct_channels.jsx @@ -6,64 +6,74 @@ var TeamStore = require('../stores/team_store.jsx'); var utils = require('../utils/utils.jsx'); module.exports = React.createClass({ + displayName: 'MoreDirectChannels', componentDidMount: function() { var self = this; - $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) { + $(this.refs.modal.getDOMNode()).on('show.bs.modal', function showModal(e) { var button = e.relatedTarget; - self.setState({ channels: $(button).data('channels') }); + self.setState({channels: $(button).data('channels')}); }); }, getInitialState: function() { - return { channels: [] }; + return {channels: []}; }, render: function() { var self = this; - var directMessageItems = this.state.channels.map(function(channel) { - var badge = ""; - var titleClass = "" + var directMessageItems = this.state.channels.map(function mapActivityToChannel(channel) { + var badge = ''; + var titleClass = ''; + var active = ''; + var handleClick = null; if (!channel.fake) { - var active = channel.id === ChannelStore.getCurrentId() ? "active" : ""; + if (channel.id === ChannelStore.getCurrentId()) { + active = 'active'; + } if (channel.unread) { - badge = {channel.unread}; - badgesActive = true; - titleClass = "unread-title" + badge = {channel.unread}; + titleClass = 'unread-title'; } + + handleClick = function clickHandler(e) { + e.preventDefault(); + utils.switchChannel(channel, channel.teammate_username); + $(self.refs.modal.getDOMNode()).modal('hide'); + }; + return ( -
  • {badge}{channel.display_name}
  • - ); - } else { - return ( -
  • {badge}{channel.display_name}
  • +
  • {badge}{channel.display_name}
  • ); } + + return ( +
  • {badge}{channel.display_name}
  • + ); }); return ( -