Merge pull request #377 from nickago/MM-1894
Mm 1894 Add state listening to the sidebar relative to the team store
Этот коммит содержится в:
@@ -128,6 +128,7 @@ module.exports = React.createClass({
|
|||||||
ChannelStore.addChangeListener(this.onChange);
|
ChannelStore.addChangeListener(this.onChange);
|
||||||
UserStore.addChangeListener(this.onChange);
|
UserStore.addChangeListener(this.onChange);
|
||||||
UserStore.addStatusesChangeListener(this.onChange);
|
UserStore.addStatusesChangeListener(this.onChange);
|
||||||
|
TeamStore.addChangeListener(this.onChange);
|
||||||
SocketStore.addChangeListener(this.onSocketChange);
|
SocketStore.addChangeListener(this.onSocketChange);
|
||||||
$('.nav-pills__container').perfectScrollbar();
|
$('.nav-pills__container').perfectScrollbar();
|
||||||
|
|
||||||
@@ -146,6 +147,7 @@ module.exports = React.createClass({
|
|||||||
ChannelStore.removeChangeListener(this.onChange);
|
ChannelStore.removeChangeListener(this.onChange);
|
||||||
UserStore.removeChangeListener(this.onChange);
|
UserStore.removeChangeListener(this.onChange);
|
||||||
UserStore.removeStatusesChangeListener(this.onChange);
|
UserStore.removeStatusesChangeListener(this.onChange);
|
||||||
|
TeamStore.removeChangeListener(this.onChange);
|
||||||
SocketStore.removeChangeListener(this.onSocketChange);
|
SocketStore.removeChangeListener(this.onSocketChange);
|
||||||
},
|
},
|
||||||
onChange: function() {
|
onChange: function() {
|
||||||
@@ -348,15 +350,16 @@ 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 clickHandler = null;
|
||||||
var href;
|
var href = '#';
|
||||||
|
var teamURL = TeamStore.getCurrentTeamUrl();
|
||||||
if (!channel.fake) {
|
if (!channel.fake) {
|
||||||
clickHandler = function(e) {
|
clickHandler = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
utils.switchChannel(channel);
|
utils.switchChannel(channel);
|
||||||
};
|
};
|
||||||
href = '#';
|
}
|
||||||
} else {
|
if (channel.fake && teamURL){
|
||||||
href = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name;
|
href = teamURL + '/channels/' + channel.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -13,89 +13,94 @@ var CHANGE_EVENT = 'change';
|
|||||||
|
|
||||||
var utils;
|
var utils;
|
||||||
function getWindowLocationOrigin() {
|
function getWindowLocationOrigin() {
|
||||||
if (!utils) utils = require('../utils/utils.jsx');
|
if (!utils) {
|
||||||
|
utils = require('../utils/utils.jsx');
|
||||||
|
}
|
||||||
return utils.getWindowLocationOrigin();
|
return utils.getWindowLocationOrigin();
|
||||||
}
|
}
|
||||||
|
|
||||||
var TeamStore = assign({}, EventEmitter.prototype, {
|
var TeamStore = assign({}, EventEmitter.prototype, {
|
||||||
emitChange: function() {
|
emitChange: function() {
|
||||||
this.emit(CHANGE_EVENT);
|
this.emit(CHANGE_EVENT);
|
||||||
},
|
},
|
||||||
addChangeListener: function(callback) {
|
addChangeListener: function(callback) {
|
||||||
this.on(CHANGE_EVENT, callback);
|
this.on(CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
removeChangeListener: function(callback) {
|
removeChangeListener: function(callback) {
|
||||||
this.removeListener(CHANGE_EVENT, callback);
|
this.removeListener(CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
get: function(id) {
|
get: function(id) {
|
||||||
var c = this._getTeams();
|
var c = this.pGetTeams();
|
||||||
return c[id];
|
return c[id];
|
||||||
},
|
},
|
||||||
getByName: function(name) {
|
getByName: function(name) {
|
||||||
var current = null;
|
var t = this.pGetTeams();
|
||||||
var t = this._getTeams();
|
|
||||||
|
|
||||||
for (id in t) {
|
for (var id in t) {
|
||||||
if (t[id].name == name) {
|
if (t[id].name === name) {
|
||||||
return t[id];
|
return t[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
getAll: function() {
|
||||||
|
return this.pGetTeams();
|
||||||
|
},
|
||||||
|
setCurrentId: function(id) {
|
||||||
|
if (id === null) {
|
||||||
|
BrowserStore.removeItem('current_team_id');
|
||||||
|
} else {
|
||||||
|
BrowserStore.setItem('current_team_id', id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getCurrentId: function() {
|
||||||
|
return BrowserStore.getItem('current_team_id');
|
||||||
|
},
|
||||||
|
getCurrent: function() {
|
||||||
|
var currentId = TeamStore.getCurrentId();
|
||||||
|
|
||||||
|
if (currentId !== null) {
|
||||||
|
return this.get(currentId);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
getCurrentTeamUrl: function() {
|
||||||
|
if (this.getCurrent()) {
|
||||||
|
return getWindowLocationOrigin() + '/' + this.getCurrent().name;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
storeTeam: function(team) {
|
||||||
|
var teams = this.pGetTeams();
|
||||||
|
teams[team.id] = team;
|
||||||
|
this.pStoreTeams(teams);
|
||||||
|
},
|
||||||
|
pStoreTeams: function(teams) {
|
||||||
|
BrowserStore.setItem('user_teams', teams);
|
||||||
|
},
|
||||||
|
pGetTeams: function() {
|
||||||
|
return BrowserStore.getItem('user_teams', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
getAll: function() {
|
|
||||||
return this._getTeams();
|
|
||||||
},
|
|
||||||
setCurrentId: function(id) {
|
|
||||||
if (id == null)
|
|
||||||
BrowserStore.removeItem("current_team_id");
|
|
||||||
else
|
|
||||||
BrowserStore.setItem("current_team_id", id);
|
|
||||||
},
|
|
||||||
getCurrentId: function() {
|
|
||||||
return BrowserStore.getItem("current_team_id");
|
|
||||||
},
|
|
||||||
getCurrent: function() {
|
|
||||||
var currentId = TeamStore.getCurrentId();
|
|
||||||
|
|
||||||
if (currentId != null)
|
|
||||||
return this.get(currentId);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
getCurrentTeamUrl: function() {
|
|
||||||
return getWindowLocationOrigin() + "/" + this.getCurrent().name;
|
|
||||||
},
|
|
||||||
storeTeam: function(team) {
|
|
||||||
var teams = this._getTeams();
|
|
||||||
teams[team.id] = team;
|
|
||||||
this._storeTeams(teams);
|
|
||||||
},
|
|
||||||
_storeTeams: function(teams) {
|
|
||||||
BrowserStore.setItem("user_teams", teams);
|
|
||||||
},
|
|
||||||
_getTeams: function() {
|
|
||||||
return BrowserStore.getItem("user_teams", {});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
TeamStore.dispatchToken = AppDispatcher.register(function(payload) {
|
TeamStore.dispatchToken = AppDispatcher.register(function registry(payload) {
|
||||||
var action = payload.action;
|
var action = payload.action;
|
||||||
|
|
||||||
switch(action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
case ActionTypes.CLICK_TEAM:
|
case ActionTypes.CLICK_TEAM:
|
||||||
TeamStore.setCurrentId(action.id);
|
TeamStore.setCurrentId(action.id);
|
||||||
TeamStore.emitChange();
|
TeamStore.emitChange();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ActionTypes.RECIEVED_TEAM:
|
case ActionTypes.RECIEVED_TEAM:
|
||||||
TeamStore.storeTeam(action.team);
|
TeamStore.storeTeam(action.team);
|
||||||
TeamStore.emitChange();
|
TeamStore.emitChange();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = TeamStore;
|
module.exports = TeamStore;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user