Skip to content

Commit cc715ec

Browse files
Merge pull request #9 from ekonstantinidis/notification-read
Read Notifications
2 parents 3c0468d + f577640 commit cc715ec

File tree

8 files changed

+86
-29
lines changed

8 files changed

+86
-29
lines changed

images/github-logo.png

3.95 KB
Loading

images/rocket.png

5.26 KB
Loading

src/js/components/login.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ var Login = React.createClass({
8383
<div className="container-fluid main-container login">
8484
<div className='row'>
8585
<div className='col-xs-offset-2 col-xs-8'>
86-
<h1>Login</h1>
86+
<img className='img-responsive logo' src='images/github-logo.png' />
87+
<div className='desc'>GitHub notifications in your menu bar.</div>
8788
<button className='btn btn-default btn-lg btn-block' onClick={this.authGithub}>
8889
<i className="fa fa-github" />Login to Gihub
8990
</button>

src/js/components/notification.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@ var apiRequests = require('../utils/api-requests');
88

99
var Notification = React.createClass({
1010

11+
getInitialState: function() {
12+
return {
13+
readClass: 'row notification',
14+
read: false
15+
};
16+
},
17+
1118
openBrowser: function () {
1219
var url = this.props.notification.subject.url.replace('api.github.com/repos', 'www.github.com');
1320
shell.openExternal(url);
1421
},
1522

1623
markAsRead: function () {
24+
var self = this;
25+
if (this.state.read) { return; }
1726
apiRequests
1827
.patchAuth('https://api.github.com/notifications/threads/' + this.props.notification.id)
1928
.end(function (err, response) {
2029
if (response && response.ok) {
2130
// Notification Read
22-
// Remove from list?
31+
self.setState({
32+
readClass: self.state.readClass + ' read',
33+
read: true
34+
});
2335
} else {
2436
// Error - Show messages.
2537
console.log(err);
@@ -39,12 +51,12 @@ var Notification = React.createClass({
3951
}
4052

4153
return (
42-
<div className='row notification'>
54+
<div className={this.state.readClass}>
4355
<div className='col-xs-1'><span className={typeIconClass} /></div>
4456
<div className='col-xs-10 subject' onClick={this.openBrowser}>
4557
{this.props.notification.subject.title}
4658
</div>
47-
<div className='col-xs-1 check-wrapper'><span className="octicon octicon-check" onClick={this.markAsRead} /></div>
59+
<div className='col-xs-1 check-wrapper'><span className='octicon octicon-check' onClick={this.markAsRead} /></div>
4860
</div>
4961
);
5062
}

src/js/components/notifications.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ var Notifications = React.createClass({
3131
this.setState( {loading: false } );
3232
},
3333

34-
openRepoBrowser: function (e) {
35-
var url = this.state.notifications[e][0].repository.html_url;
36-
shell.openExternal(url);
37-
},
38-
3934
render: function () {
4035
var notifications;
36+
var wrapperClass = 'container-fluid main-container notifications';
4137
var self = this;
4238

4339
if (!_.isEmpty(this.state.notifications)) {
@@ -48,16 +44,18 @@ var Notifications = React.createClass({
4844
})
4945
);
5046
} else {
47+
wrapperClass += ' all-read';
5148
notifications = (
52-
<div className="all-read">
49+
<div>
5350
<h2>There are no notifications for you.</h2>
5451
<h3>All clean!</h3>
52+
<img className='img-responsive emoji' src='images/rocket.png' />
5553
</div>
5654
);
5755
}
5856

5957
return (
60-
<div className="container-fluid main-container notifications">
58+
<div className={wrapperClass}>
6159
<Loading className='loading-container' shouldShow={this.state.loading}>
6260
<div className='loading-text'>working on it</div>
6361
</Loading>

src/js/components/repository.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
var React = require('react');
2-
var SingleNotification = require('../components/notification');
32
var _ = require('underscore');
3+
var remote = window.require('remote');
4+
var shell = remote.require('shell');
5+
6+
var SingleNotification = require('../components/notification');
47

58
var Repository = React.createClass({
69

710
getAvatar: function () {
811
return this.props.repo[0].repository.owner.avatar_url;
912
},
1013

14+
openBrowser: function () {
15+
var url = this.props.repo[0].repository.html_url;
16+
shell.openExternal(url);
17+
},
18+
1119
render: function () {
1220
var notifications = (
1321
_.map(this.props.repo, function(notification, i) {
@@ -21,7 +29,7 @@ var Repository = React.createClass({
2129
<div>
2230
<div className='row repository'>
2331
<div className='col-xs-2'><img className='avatar' src={this.getAvatar()} /></div>
24-
<div className='col-xs-10 name'>{this.props.repoName}</div>
32+
<div className='col-xs-10 name' onClick={this.openBrowser}>{this.props.repoName}</div>
2533
</div>
2634
{notifications}
2735
</div>

src/js/utils/api-requests.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,29 @@ var apiRequests = {
88
.set('Accept', 'application/json');
99
},
1010

11-
getAuth: function (url) {
12-
return request
13-
.get(url)
14-
.set('Accept', 'application/json')
15-
.set('Authorization', 'token ' + AuthStore.authStatus());
16-
},
17-
1811
post: function (url, params) {
1912
return request
2013
.post(url)
2114
.send(params)
22-
.set('Accept', 'application/json');
15+
.set('Accept', 'application/json')
16+
.set('User-Agent', 'Gitify');
2317
},
2418

25-
putAuth: function (url, params) {
19+
getAuth: function (url) {
2620
return request
27-
.put(url)
28-
.send(params)
29-
.set('Accept', 'application/json')
30-
.set('Authorization', 'token ' + AuthStore.authStatus());
21+
.get(url)
22+
.set('Accept', 'application/vnd.github.v3+json')
23+
.set('Authorization', 'token ' + AuthStore.authStatus())
24+
.set('User-Agent', 'Gitify');
3125
},
3226

3327
patchAuth: function (url, params) {
3428
return request
3529
.patch(url)
3630
.send(params)
37-
.set('Authorization', 'token ' + AuthStore.authStatus());
31+
.set('Accept', 'application/vnd.github.v3+json')
32+
.set('Authorization', 'token ' + AuthStore.authStatus())
33+
.set('User-Agent', 'Gitify');
3834
}
3935
};
4036

src/less/style.less

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@ThemeBlack: #262626;
1414
@ThemeGreen: #6cc644;
1515

16+
@ThemeBlue: #4183c4;
17+
1618
@White: #ffffff;
1719

1820
/* @end Colors */
@@ -89,6 +91,13 @@
8991
text-overflow: ellipsis;
9092
}
9193

94+
// Opacity
95+
.Opacity(@opacity: 0.5) {
96+
-webkit-opacity: @opacity;
97+
-moz-opacity: @opacity;
98+
opacity: @opacity;
99+
}
100+
92101
/* @end Mixins */
93102

94103

@@ -219,7 +228,7 @@ html, body {
219228
/* @group Component / Login */
220229

221230
.login {
222-
background-color: @ThemeGreen;
231+
background-color: @ThemeBlack;
223232
color: @White;
224233
position: absolute;
225234
top: @navbar-height;
@@ -232,6 +241,12 @@ html, body {
232241
max-width: 150px;
233242
margin: 10px auto 20px;
234243
}
244+
245+
.desc {
246+
font-size: 20px;
247+
text-align: center;
248+
margin-bottom: 20px;
249+
}
235250
}
236251

237252
/* @end Component / Login */
@@ -266,10 +281,19 @@ html, body {
266281
margin: 0;
267282
padding: 0;
268283

269-
.all-read {
284+
&.all-read {
285+
background-color: @ThemeBlack;
286+
color: @White;
287+
padding: 30px 20px;
288+
270289
h2, h3 {
271290
text-align: center;
272291
}
292+
293+
.emoji {
294+
margin: 15px auto;
295+
296+
}
273297
}
274298
}
275299

@@ -283,6 +307,10 @@ html, body {
283307
padding: 3px 20px;
284308
border-bottom: 1px solid darken(#f5f5f5, 10%);
285309

310+
transition: opacity .25s ease-in-out;
311+
-moz-transition: opacity .25s ease-in-out;
312+
-webkit-transition: opacity .25s ease-in-out;
313+
286314
.col-xs-1,
287315
.col-xs-10 {
288316
padding: 5px 0;
@@ -301,6 +329,20 @@ html, body {
301329
.octicon {
302330
margin-right: 10px;
303331
font-size: 20px;
332+
333+
&.octicon-check {
334+
-webkit-transition: all .8s;
335+
-moz-transition: all .8s;
336+
transition: all .8s;
337+
338+
&:hover {
339+
color: @ThemeBlue;
340+
}
341+
}
342+
}
343+
344+
&.read {
345+
.Opacity(0.4);
304346
}
305347
}
306348

0 commit comments

Comments
 (0)