Skip to content

Commit 18beb30

Browse files
Merge pull request #6 from ekonstantinidis/group-notifications
Group notifications by repo
2 parents 9ebdd29 + e3c5a06 commit 18beb30

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/js/components/notifications.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var React = require('react');
22
var Reflux = require('reflux');
3+
var _ = require('underscore');
34
var Loading = require('reloading');
45

56
var Actions = require('../actions/actions');
@@ -15,7 +16,7 @@ var Notifications = React.createClass({
1516

1617
getInitialState: function() {
1718
return {
18-
notifications: [],
19+
notifications: {},
1920
loading: true
2021
};
2122
},
@@ -31,10 +32,19 @@ var Notifications = React.createClass({
3132
render: function () {
3233
var notifications;
3334

34-
if (this.state.notifications.length > 0) {
35+
if (!_.isEmpty(this.state.notifications)) {
3536
notifications = (
36-
this.state.notifications.map(function(object, i){
37-
return <SingleNotification key={object.id} notification={object} />;
37+
_.map(this.state.notifications, function(repo, i) {
38+
return (
39+
<div key={i}>
40+
<h4>{i}</h4>
41+
{repo.map(function(as, df) {
42+
return (
43+
<SingleNotification notification={as} key={as.id} />
44+
);
45+
})}
46+
</div>
47+
);
3848
})
3949
);
4050
} else {

src/js/stores/notifications.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ var NotificationsStore = Reflux.createStore({
4040
},
4141

4242
onGetNotificationsCompleted: function (notifications) {
43-
this._notifications = notifications;
44-
this.trigger(this._notifications);
43+
var groupedNotifications = _.groupBy(notifications, function(object){
44+
return object.repository.name;
45+
});
46+
47+
this._notifications = groupedNotifications;
48+
this.trigger(groupedNotifications);
4549
},
4650

4751
onGetNotificationsFailed: function (error) {

0 commit comments

Comments
 (0)