Skip to content

Commit dedba96

Browse files
Merge pull request #36 from ekonstantinidis/show-message-onerror
Show message if errors getting the notifications
2 parents 53c8cd0 + 4b08954 commit dedba96

File tree

6 files changed

+52
-17
lines changed

6 files changed

+52
-17
lines changed

images/all-read.png

8.51 KB
Loading

images/error.png

7.88 KB
Loading

images/rocket.png

-5.26 KB
Binary file not shown.

src/js/__tests__/components/notifications.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ describe('Test for Notifications Component', function () {
7070
expect(instance.state.loading).toBeTruthy();
7171
instance.completedNotifications();
7272
expect(instance.state.loading).toBeFalsy();
73+
expect(instance.state.errors).toBeFalsy();
74+
75+
var errors = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'errored');
76+
expect(errors.length).toBe(0);
77+
78+
instance.failedNotifications();
79+
expect(instance.state.loading).toBeFalsy();
80+
expect(instance.state.errors).toBeTruthy();
81+
82+
errors = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'errored');
83+
expect(errors.length).toBe(1);
7384

7485
});
7586

src/js/components/notifications.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ var Notifications = React.createClass({
1313
mixins: [
1414
Reflux.connect(NotificationsStore, 'notifications'),
1515
Reflux.listenTo(Actions.getNotifications.completed, 'completedNotifications'),
16-
Reflux.listenTo(Actions.getNotifications.failed, 'completedNotifications')
16+
Reflux.listenTo(Actions.getNotifications.failed, 'failedNotifications')
1717
],
1818

1919
getInitialState: function () {
2020
return {
2121
notifications: [],
22-
loading: true
22+
loading: true,
23+
errors: false
2324
};
2425
},
2526

@@ -28,36 +29,58 @@ var Notifications = React.createClass({
2829
},
2930

3031
completedNotifications: function () {
31-
this.setState( {loading: false } );
32+
this.setState({
33+
loading: false,
34+
errors: false
35+
});
36+
},
37+
38+
failedNotifications: function () {
39+
this.setState({
40+
loading: false,
41+
errors: true
42+
});
3243
},
3344

3445
render: function () {
35-
var notifications;
46+
var notifications, errors;
3647
var wrapperClass = 'container-fluid main-container notifications';
3748

38-
if (_.isEmpty(this.state.notifications)) {
39-
wrapperClass += ' all-read';
40-
notifications = (
49+
if (this.state.errors) {
50+
wrapperClass += ' errored';
51+
errors = (
4152
<div>
42-
<h2>There are no notifications for you.</h2>
43-
<h3>All clean!</h3>
44-
<img className='img-responsive emoji' src='images/rocket.png' />
53+
<h3>Oops something went wrong.</h3>
54+
<h4>Couldn't get your notifications.</h4>
55+
<img className='img-responsive emoji' src='images/error.png' />
4556
</div>
4657
);
4758
} else {
48-
notifications = (
49-
this.state.notifications.map(function (obj) {
50-
var repoFullName = obj[0].repository.full_name;
51-
return <Repository repo={obj} repoName={repoFullName} key={repoFullName} />;
52-
})
53-
);
59+
if (_.isEmpty(this.state.notifications)) {
60+
wrapperClass += ' all-read';
61+
notifications = (
62+
<div>
63+
<h2>There are no notifications for you.</h2>
64+
<h3>All clean!</h3>
65+
<img className='img-responsive emoji' src='images/all-read.png' />
66+
</div>
67+
);
68+
} else {
69+
notifications = (
70+
this.state.notifications.map(function (obj) {
71+
var repoFullName = obj[0].repository.full_name;
72+
return <Repository repo={obj} repoName={repoFullName} key={repoFullName} />;
73+
})
74+
);
75+
}
5476
}
5577

5678
return (
5779
<div className={wrapperClass}>
5880
<Loading className='loading-container' shouldShow={this.state.loading}>
5981
<div className='loading-text'>working on it</div>
6082
</Loading>
83+
{errors}
6184
{notifications}
6285
</div>
6386
);

src/less/style.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,13 @@ html, body {
288288
margin: 0;
289289
padding: 0;
290290

291+
&.errored,
291292
&.all-read {
292293
background-color: @ThemeBlack;
293294
color: @White;
294295
padding: 30px 20px;
295296

296-
h2, h3 {
297+
h2, h3, h4 {
297298
text-align: center;
298299
}
299300

0 commit comments

Comments
 (0)