Merge pull request #680 from hmhealey/plt159

PLT-159 Properly hide unread indicators when there are no unread channels
Этот коммит содержится в:
Joram Wilander
2015-09-17 07:49:29 -04:00
родитель e644b53b72 acf2fb64b4
Коммит 936f032ec4
2 изменённых файлов: 73 добавлений и 33 удалений

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

@@ -13,6 +13,7 @@ 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 NewChannelFlow = require('./new_channel_flow.jsx'); var NewChannelFlow = require('./new_channel_flow.jsx');
var UnreadChannelIndicator = require('./unread_channel_indicator.jsx');
export default class Sidebar extends React.Component { export default class Sidebar extends React.Component {
constructor(props) { constructor(props) {
@@ -153,6 +154,16 @@ export default class Sidebar extends React.Component {
$(window).on('resize', this.onResize); $(window).on('resize', this.onResize);
} }
shouldComponentUpdate(nextProps, nextState) {
if (!Utils.areStatesEqual(nextProps, this.props)) {
return true;
}
if (!Utils.areStatesEqual(nextState, this.state)) {
return true;
}
return false;
}
componentDidUpdate() { componentDidUpdate() {
this.updateTitle(); this.updateTitle();
this.updateUnreadIndicators(); this.updateUnreadIndicators();
@@ -274,15 +285,16 @@ export default class Sidebar extends React.Component {
this.updateUnreadIndicators(); this.updateUnreadIndicators();
} }
updateUnreadIndicators() { updateUnreadIndicators() {
var container = $(React.findDOMNode(this.refs.container)); const container = $(React.findDOMNode(this.refs.container));
var showTopUnread = false;
var showBottomUnread = false;
if (this.firstUnreadChannel) { if (this.firstUnreadChannel) {
var firstUnreadElement = $(React.findDOMNode(this.refs[this.firstUnreadChannel])); var firstUnreadElement = $(React.findDOMNode(this.refs[this.firstUnreadChannel]));
if (firstUnreadElement.position().top + firstUnreadElement.height() < 0) { if (firstUnreadElement.position().top + firstUnreadElement.height() < 0) {
$(React.findDOMNode(this.refs.topUnreadIndicator)).css('display', 'initial'); showTopUnread = true;
} else {
$(React.findDOMNode(this.refs.topUnreadIndicator)).css('display', 'none');
} }
} }
@@ -290,11 +302,14 @@ export default class Sidebar extends React.Component {
var lastUnreadElement = $(React.findDOMNode(this.refs[this.lastUnreadChannel])); var lastUnreadElement = $(React.findDOMNode(this.refs[this.lastUnreadChannel]));
if (lastUnreadElement.position().top > container.height()) { if (lastUnreadElement.position().top > container.height()) {
$(React.findDOMNode(this.refs.bottomUnreadIndicator)).css('display', 'initial'); showBottomUnread = true;
} else {
$(React.findDOMNode(this.refs.bottomUnreadIndicator)).css('display', 'none');
} }
} }
this.setState({
showTopUnread,
showBottomUnread
});
} }
createChannelElement(channel, index) { createChannelElement(channel, index) {
var members = this.state.members; var members = this.state.members;
@@ -432,19 +447,13 @@ export default class Sidebar extends React.Component {
this.lastUnreadChannel = null; this.lastUnreadChannel = null;
// create elements for all 3 types of channels // create elements for all 3 types of channels
var channelItems = this.state.channels.filter( const publicChannels = this.state.channels.filter((channel) => channel.type === 'O');
function filterPublicChannels(channel) { const publicChannelItems = publicChannels.map(this.createChannelElement);
return channel.type === 'O';
}
).map(this.createChannelElement);
var privateChannelItems = this.state.channels.filter( const privateChannels = this.state.channels.filter((channel) => channel.type === 'P');
function filterPrivateChannels(channel) { const privateChannelItems = privateChannels.map(this.createChannelElement);
return channel.type === 'P';
}
).map(this.createChannelElement);
var directMessageItems = this.state.showDirectChannels.map(this.createChannelElement); const directMessageItems = this.state.showDirectChannels.map(this.createChannelElement);
// update the favicon to show if there are any notifications // update the favicon to show if there are any notifications
var link = document.createElement('link'); var link = document.createElement('link');
@@ -498,20 +507,16 @@ export default class Sidebar extends React.Component {
/> />
<SearchBox /> <SearchBox />
<div <UnreadChannelIndicator
ref='topUnreadIndicator' show={this.state.showTopUnread}
className='nav-pills__unread-indicator nav-pills__unread-indicator-top' extraClass='nav-pills__unread-indicator-top'
style={{display: 'none'}} text={'Unread post(s) above'}
> />
Unread post(s) above <UnreadChannelIndicator
</div> show={this.state.showBottomUnread}
<div extraClass='nav-pills__unread-indicator-bottom'
ref='bottomUnreadIndicator' text={'Unread post(s) below'}
className='nav-pills__unread-indicator nav-pills__unread-indicator-bottom' />
style={{display: 'none'}}
>
Unread post(s) below
</div>
<div <div
ref='container' ref='container'
@@ -531,7 +536,7 @@ export default class Sidebar extends React.Component {
</a> </a>
</h4> </h4>
</li> </li>
{channelItems} {publicChannelItems}
<li> <li>
<a <a
href='#' href='#'

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

@@ -0,0 +1,35 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
// Indicator for the left sidebar which indicate if there's unread posts in a channel that is not shown
// because it is either above or below the screen
export default class UnreadChannelIndicator extends React.Component {
constructor(props) {
super(props);
}
render() {
let displayValue = 'none';
if (this.props.show) {
displayValue = 'initial';
}
return (
<div
className={'nav-pills__unread-indicator ' + this.props.extraClass}
style={{display: displayValue}}
>
{this.props.text}
</div>
);
}
}
UnreadChannelIndicator.defaultProps = {
show: false,
extraClass: '',
text: ''
};
UnreadChannelIndicator.propTypes = {
show: React.PropTypes.bool,
extraClass: React.PropTypes.string,
text: React.PropTypes.string
};