simple room filtering

This commit is contained in:
Galen Wolfe-Pauly 2017-02-12 20:49:42 -08:00 committed by Raymond Pasco
parent 08f6a52f00
commit 88acfe89b1

View File

@ -9,6 +9,17 @@ _persistence = require('../persistence/MessagePersistence.coffee');
Persistence = _persistence({ Persistence = _persistence({
MessageActions: module.exports = { MessageActions: module.exports = {
setFilter: function(station) {
return Dispatcher.handleViewAction({
station: station,
type: "messages-filter"
});
},
clearFilter: function() {
return Dispatcher.handleViewAction({
type: "messages-filter-clear"
});
},
loadMessages: function(messages, last, get) { loadMessages: function(messages, last, get) {
return Dispatcher.handleServerAction({ return Dispatcher.handleServerAction({
messages: messages, messages: messages,
@ -800,7 +811,7 @@ module.exports = recl({
},{"../actions/MessageActions.coffee":1,"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MessageComponent.coffee":5}],7:[function(require,module,exports){ },{"../actions/MessageActions.coffee":1,"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MessageComponent.coffee":5}],7:[function(require,module,exports){
var Load, Member, MessageStore, StationActions, StationStore, a, clas, div, h1, h2, input, label, recl, ref, rele, span, style, util, var Load, Member, MessageActions, MessageStore, StationActions, StationStore, a, clas, div, h1, h2, input, label, recl, ref, rele, span, style, util,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
util = require('../util.coffee'); util = require('../util.coffee');
@ -817,6 +828,8 @@ MessageStore = require('../stores/MessageStore.coffee');
StationStore = require('../stores/StationStore.coffee'); StationStore = require('../stores/StationStore.coffee');
MessageActions = require('../actions/MessageActions.coffee');
StationActions = require('../actions/StationActions.coffee'); StationActions = require('../actions/StationActions.coffee');
Member = require('./MemberComponent.coffee'); Member = require('./MemberComponent.coffee');
@ -831,6 +844,7 @@ module.exports = recl({
audi: StationStore.getAudience(), audi: StationStore.getAudience(),
members: StationStore.getMembers(), members: StationStore.getMembers(),
station: util.mainStation(), station: util.mainStation(),
filter: MessageStore.getFilter(),
stations: StationStore.getStations(), stations: StationStore.getStations(),
configs: StationStore.getConfigs(), configs: StationStore.getConfigs(),
fetching: MessageStore.getFetching(), fetching: MessageStore.getFetching(),
@ -844,6 +858,7 @@ module.exports = recl({
}, },
componentDidMount: function() { componentDidMount: function() {
this.$el = $(ReactDOM.findDOMNode()); this.$el = $(ReactDOM.findDOMNode());
MessageStore.addChangeListener(this._onChangeStore);
StationStore.addChangeListener(this._onChangeStore); StationStore.addChangeListener(this._onChangeStore);
if (this.state.listening.indexOf(this.state.station) === -1) { if (this.state.listening.indexOf(this.state.station) === -1) {
return StationActions.listenStation(this.state.station); return StationActions.listenStation(this.state.station);
@ -888,10 +903,8 @@ module.exports = recl({
} }
}, },
_openStation: function(e) { _openStation: function(e) {
var $t;
$t = $(e.target);
return this.setState({ return this.setState({
open: $t.attr('data-station') open: $(e.target).attr('data-station')
}); });
}, },
_closeStation: function() { _closeStation: function() {
@ -899,6 +912,15 @@ module.exports = recl({
open: null open: null
}); });
}, },
_filterStation: function(e) {
var station;
station = $(e.target).attr('data-station');
if (this.state.filter !== station) {
return MessageActions.setFilter(station);
} else {
return MessageActions.clearFilter();
}
},
_remove: function(e) { _remove: function(e) {
var _sources, _station; var _sources, _station;
e.stopPropagation(); e.stopPropagation();
@ -969,10 +991,14 @@ module.exports = recl({
onClick: this._openStation, onClick: this._openStation,
"data-station": source "data-station": source
}, source), div({ }, source), div({
className: "close", className: 'options'
}, div({
onClick: this._filterStation,
"data-station": source
}, this.state.filter === source ? "Clear" : "Filter"), div({
onClick: this._remove, onClick: this._remove,
"data-station": source "data-station": source
}, "✕"))); }, "Leave"))));
} }
return results; return results;
}).call(this); }).call(this);
@ -1010,7 +1036,7 @@ module.exports = recl({
}); });
},{"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MemberComponent.coffee":4,"classnames":16}],8:[function(require,module,exports){ },{"../actions/MessageActions.coffee":1,"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MemberComponent.coffee":4,"classnames":16}],8:[function(require,module,exports){
var Audience, Member, MessageActions, MessageStore, PO, SHIPSHAPE, StationActions, StationStore, br, div, husl, input, recl, ref, textToHTML, textarea, util, var Audience, Member, MessageActions, MessageStore, PO, SHIPSHAPE, StationActions, StationStore, br, div, husl, input, recl, ref, textToHTML, textarea, util,
hasProp = {}.hasOwnProperty; hasProp = {}.hasOwnProperty;
@ -1747,7 +1773,7 @@ module.exports = function(arg) {
},{"../util.coffee":15}],13:[function(require,module,exports){ },{"../util.coffee":15}],13:[function(require,module,exports){
var EventEmitter, MessageDispatcher, MessageStore, _fetching, _last, _listening, _messages, _station, _typing, moment; var EventEmitter, MessageDispatcher, MessageStore, _fetching, _filter, _last, _listening, _messages, _station, _typing, moment;
moment = window.moment.tz; moment = window.moment.tz;
@ -1763,6 +1789,8 @@ _last = null;
_station = null; _station = null;
_filter = null;
_listening = []; _listening = [];
_typing = false; _typing = false;
@ -1822,6 +1850,15 @@ MessageStore = _.merge(new EventEmitter, {
setStation: function(station) { setStation: function(station) {
return _station = station; return _station = station;
}, },
getFilter: function() {
return _filter;
},
setFilter: function(station) {
return _filter = station;
},
clearFilter: function(station) {
return _filter = null;
},
sendMessage: function(message) { sendMessage: function(message) {
return _messages[message.thought.serial] = message; return _messages[message.thought.serial] = message;
}, },
@ -1840,7 +1877,21 @@ MessageStore = _.merge(new EventEmitter, {
return _fetching = false; return _fetching = false;
}, },
getAll: function() { getAll: function() {
return _.values(_messages); var mess;
mess = _.values(_messages);
if (!_filter) {
return mess;
} else {
return _.filter(mess, function(mess) {
var audi;
audi = _.keys(mess.thought.audience);
if (audi.indexOf(_filter) !== -1) {
return true;
} else {
return false;
}
});
}
}, },
getFetching: function() { getFetching: function() {
return _fetching; return _fetching;
@ -1862,6 +1913,14 @@ MessageStore.dispatchToken = MessageDispatcher.register(function(payload) {
case 'station-switch': case 'station-switch':
MessageStore.setStation(action.station); MessageStore.setStation(action.station);
break; break;
case 'messages-filter':
MessageStore.setFilter(action.station);
MessageStore.emitChange();
break;
case 'messages-filter-clear':
MessageStore.clearFilter(action.station);
MessageStore.emitChange();
break;
case 'messages-listen': case 'messages-listen':
MessageStore.setListening(action.station); MessageStore.setListening(action.station);
MessageStore.emitChange(); MessageStore.emitChange();