Refactored the NotifyCounts component out of the navbar.jsx file into its own file
Этот коммит содержится в:
@@ -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 utils = require('../utils/utils.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');
|
||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
@@ -10,54 +9,12 @@ var TeamStore = require('../stores/team_store.jsx');
|
|||||||
|
|
||||||
var UserProfile = require('./user_profile.jsx');
|
var UserProfile = require('./user_profile.jsx');
|
||||||
var MessageWrapper = require('./message_wrapper.jsx');
|
var MessageWrapper = require('./message_wrapper.jsx');
|
||||||
|
var NotifyCounts = require('./notify_counts.jsx');
|
||||||
|
|
||||||
var Constants = require('../utils/constants.jsx');
|
var Constants = require('../utils/constants.jsx');
|
||||||
var ActionTypes = Constants.ActionTypes;
|
var ActionTypes = Constants.ActionTypes;
|
||||||
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
||||||
|
|
||||||
function getCountsStateFromStores() {
|
|
||||||
var count = 0;
|
|
||||||
var channels = ChannelStore.getAll();
|
|
||||||
var members = ChannelStore.getAllMembers();
|
|
||||||
|
|
||||||
channels.forEach(function setChannelInfo(channel) {
|
|
||||||
var channelMember = members[channel.id];
|
|
||||||
if (channel.type === 'D') {
|
|
||||||
count += channel.total_msg_count - channelMember.msg_count;
|
|
||||||
} else if (channelMember.mention_count > 0) {
|
|
||||||
count += channelMember.mention_count;
|
|
||||||
} else if (channelMember.notify_level !== 'quiet' && channel.total_msg_count - channelMember.msg_count > 0) {
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {count: count};
|
|
||||||
}
|
|
||||||
|
|
||||||
var NotifyCounts = React.createClass({
|
|
||||||
componentDidMount: function() {
|
|
||||||
ChannelStore.addChangeListener(this.onListenerChange);
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
ChannelStore.removeChangeListener(this.onListenerChange);
|
|
||||||
},
|
|
||||||
onListenerChange: function() {
|
|
||||||
var newState = getCountsStateFromStores();
|
|
||||||
if (!utils.areStatesEqual(newState, this.state)) {
|
|
||||||
this.setState(newState);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
|
||||||
return getCountsStateFromStores();
|
|
||||||
},
|
|
||||||
render: function() {
|
|
||||||
if (this.state.count) {
|
|
||||||
return <span className='badge badge-notify'>{this.state.count}</span>;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function getStateFromStores() {
|
function getStateFromStores() {
|
||||||
return {
|
return {
|
||||||
channel: ChannelStore.getCurrent(),
|
channel: ChannelStore.getCurrent(),
|
||||||
|
|||||||
49
web/react/components/notify_counts.jsx
Обычный файл
49
web/react/components/notify_counts.jsx
Обычный файл
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
var utils = require('../utils/utils.jsx');
|
||||||
|
var ChannelStore = require('../stores/channel_store.jsx');
|
||||||
|
|
||||||
|
function getCountsStateFromStores() {
|
||||||
|
var count = 0;
|
||||||
|
var channels = ChannelStore.getAll();
|
||||||
|
var members = ChannelStore.getAllMembers();
|
||||||
|
|
||||||
|
channels.forEach(function setChannelInfo(channel) {
|
||||||
|
var channelMember = members[channel.id];
|
||||||
|
if (channel.type === 'D') {
|
||||||
|
count += channel.total_msg_count - channelMember.msg_count;
|
||||||
|
} else if (channelMember.mention_count > 0) {
|
||||||
|
count += channelMember.mention_count;
|
||||||
|
} else if (channelMember.notify_level !== 'quiet' && channel.total_msg_count - channelMember.msg_count > 0) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {count: count};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = React.createClass({
|
||||||
|
displayName: 'NotifyCounts',
|
||||||
|
componentDidMount: function() {
|
||||||
|
ChannelStore.addChangeListener(this.onListenerChange);
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
ChannelStore.removeChangeListener(this.onListenerChange);
|
||||||
|
},
|
||||||
|
onListenerChange: function() {
|
||||||
|
var newState = getCountsStateFromStores();
|
||||||
|
if (!utils.areStatesEqual(newState, this.state)) {
|
||||||
|
this.setState(newState);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getInitialState: function() {
|
||||||
|
return getCountsStateFromStores();
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
if (this.state.count) {
|
||||||
|
return <span className='badge badge-notify'>{this.state.count}</span>;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
Ссылка в новой задаче
Block a user