Cosmetic reformatting of sidebar.jsx

Этот коммит содержится в:
Reed Garmsen
2015-08-14 17:39:50 -07:00
родитель 2b80620cee
Коммит e149bc6212

Просмотреть файл

@@ -1,7 +1,6 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var ChannelStore = require('../stores/channel_store.jsx'); var ChannelStore = require('../stores/channel_store.jsx');
var Client = require('../utils/client.jsx'); var Client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_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 utils = require('../utils/utils.jsx');
var SidebarHeader = require('./sidebar_header.jsx'); var SidebarHeader = require('./sidebar_header.jsx');
var SearchBox = require('./search_bar.jsx'); var SearchBox = require('./search_bar.jsx');
var Constants = require('../utils/constants.jsx'); var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
function getStateFromStores() { function getStateFromStores() {
var members = ChannelStore.getAllMembers(); 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 we don't have MAX_DMS unread channels, sort the read list by last_post_at
if (showDirectChannels.length < Constants.MAX_DMS) { if (showDirectChannels.length < Constants.MAX_DMS) {
readDirectChannels.sort(function(a, b) { readDirectChannels.sort(function sortByLastPost(a, b) {
// sort by last_post_at first // sort by last_post_at first
if (a.last_post_at > b.last_post_at) { if (a.last_post_at > b.last_post_at) {
return -1; return -1;
@@ -126,6 +123,10 @@ function getStateFromStores() {
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'Sidebar', displayName: 'Sidebar',
propTypes: {
teamType: React.PropTypes.string,
teamDisplayName: React.PropTypes.string
},
componentDidMount: function() { componentDidMount: function() {
ChannelStore.addChangeListener(this.onChange); ChannelStore.addChangeListener(this.onChange);
UserStore.addChangeListener(this.onChange); UserStore.addChangeListener(this.onChange);
@@ -246,17 +247,17 @@ module.exports = React.createClass({
var channel = ChannelStore.getCurrent(); var channel = ChannelStore.getCurrent();
if (channel) { if (channel) {
if (channel.type === 'D') { if (channel.type === 'D') {
var teammate_username = utils.getDirectTeammate(channel.id).username; var teammateUsername = utils.getDirectTeammate(channel.id).username;
document.title = teammate_username + ' ' + document.title.substring(document.title.lastIndexOf('-')); document.title = teammateUsername + ' ' + document.title.substring(document.title.lastIndexOf('-'));
} else { } else {
document.title = channel.display_name + ' ' + document.title.substring(document.title.lastIndexOf('-')); document.title = channel.display_name + ' ' + document.title.substring(document.title.lastIndexOf('-'));
} }
} }
}, },
onScroll: function(e) { onScroll: function() {
this.updateUnreadIndicators(); this.updateUnreadIndicators();
}, },
onResize: function(e) { onResize: function() {
this.updateUnreadIndicators(); this.updateUnreadIndicators();
}, },
updateUnreadIndicators: function() { updateUnreadIndicators: function() {
@@ -301,6 +302,7 @@ module.exports = React.createClass({
function createChannelElement(channel, index) { function createChannelElement(channel, index) {
var channelMember = members[channel.id]; var channelMember = members[channel.id];
var msgCount;
var linkClass = ''; var linkClass = '';
if (channel.id === activeId) { if (channel.id === activeId) {
@@ -309,7 +311,7 @@ module.exports = React.createClass({
var unread = false; var unread = false;
if (channelMember) { 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; unread = (msgCount > 0 && channelMember.notify_level !== 'quiet') || channelMember.mention_count > 0;
} }
@@ -327,7 +329,7 @@ module.exports = React.createClass({
if (channelMember) { if (channelMember) {
if (channel.type === 'D') { if (channel.type === 'D') {
// direct message channels show badges for any number of unread posts // 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) { if (msgCount > 0) {
badge = <span className='badge pull-right small'>{msgCount}</span>; badge = <span className='badge pull-right small'>{msgCount}</span>;
badgesActive = true; 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) // 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 href = '#';
var teamURL = TeamStore.getCurrentTeamUrl(); var teamURL = TeamStore.getCurrentTeamUrl();
if (!channel.fake) { if (!channel.fake) {
clickHandler = function(e) { handleClick = function clickHandler(e) {
e.preventDefault(); e.preventDefault();
utils.switchChannel(channel); utils.switchChannel(channel);
}; };
@@ -378,17 +380,17 @@ module.exports = React.createClass({
otherUserId = ids[0]; otherUserId = ids[0];
} }
clickHandler = function(e) { handleClick = function clickHandler(e) {
e.preventDefault(); e.preventDefault();
self.setState({loadingPMChannel: index}); self.setState({loadingPMChannel: index});
Client.createPMChannelIfNotExists(channel, otherUserId, Client.createPMChannelIfNotExists(channel, otherUserId,
function(data) { function success(data) {
self.setState({loadingPMChannel: -1}); self.setState({loadingPMChannel: -1});
AsyncClient.getChannel(data.id); AsyncClient.getChannel(data.id);
utils.switchChannel(data); utils.switchChannel(data);
}, },
function() { function error() {
self.setState({loadingPMChannel: -1}); self.setState({loadingPMChannel: -1});
window.location.href = teamURL + '/channels/' + channel.name; window.location.href = teamURL + '/channels/' + channel.name;
} }
@@ -398,24 +400,24 @@ module.exports = React.createClass({
return ( return (
<li key={channel.name} ref={channel.name} className={linkClass}> <li key={channel.name} ref={channel.name} className={linkClass}>
<a className={'sidebar-channel ' + titleClass} href={href} onClick={clickHandler}> <a className={'sidebar-channel ' + titleClass} href={href} onClick={handleClick}>
{status} {status}
{channel.display_name} {channel.display_name}
{badge} {badge}
</a> </a>
</li> </li>
); );
}; }
// create elements for all 3 types of channels // create elements for all 3 types of channels
var channelItems = this.state.channels.filter( var channelItems = this.state.channels.filter(
function(channel) { function filterPublicChannels(channel) {
return channel.type === 'O'; return channel.type === 'O';
} }
).map(createChannelElement); ).map(createChannelElement);
var privateChannelItems = this.state.channels.filter( var privateChannelItems = this.state.channels.filter(
function(channel) { function filterPrivateChannels(channel) {
return channel.type === 'P'; return channel.type === 'P';
} }
).map(createChannelElement); ).map(createChannelElement);
@@ -444,7 +446,7 @@ module.exports = React.createClass({
directMessageMore = ( directMessageMore = (
<li> <li>
<a href='#' data-toggle='modal' className='nav-more' data-target='#more_direct_channels' data-channels={JSON.stringify(this.state.hideDirectChannels)}> <a href='#' data-toggle='modal' className='nav-more' data-target='#more_direct_channels' data-channels={JSON.stringify(this.state.hideDirectChannels)}>
{'More ('+this.state.hideDirectChannels.length+')'} {'More (' + this.state.hideDirectChannels.length + ')'}
</a> </a>
</li> </li>
); );