Skip to content

Commit 856311f

Browse files
Merge pull request #105 from ekonstantinidis/on-click-mark-read
Settings - "On Click, Mark as Read"
2 parents 6959cbd + e7659f6 commit 856311f

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

src/js/__tests__/components/notification.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jest.dontMock('../../utils/api-requests');
66
jest.dontMock('../../components/notification.js');
77
jest.dontMock('../../stores/auth.js');
88
jest.dontMock('../../stores/notifications.js');
9+
jest.dontMock('../../stores/settings.js');
910

1011
var React = require('react/addons');
1112
var TestUtils = React.addons.TestUtils;
@@ -48,6 +49,7 @@ describe('Test for Notification Component', function () {
4849
AuthStore = require('../../stores/auth.js');
4950
SingleNotification = require('../../components/notification.js');
5051
NotificationsStore = require('../../stores/notifications.js');
52+
SettingsStore = require('../../stores/settings.js');
5153
});
5254

5355
it('Should render a notification component (Issue)', function () {
@@ -72,12 +74,28 @@ describe('Test for Notification Component', function () {
7274
key={notification.id} />);
7375

7476
expect(instance.state.isRead).toBeFalsy();
77+
expect(instance.pressTitle).toBeDefined();
7578
expect(instance.openBrowser).toBeDefined();
7679
expect(instance.markAsRead).toBeDefined();
7780

81+
spyOn(instance, 'openBrowser');
82+
spyOn(instance, 'markAsRead');
83+
84+
instance.pressTitle();
85+
expect(instance.openBrowser).toHaveBeenCalled();
86+
7887
// Open Browser
7988
instance.openBrowser();
8089

90+
// If 'markOnClick' is ON
91+
SettingsStore.onSetSetting('markOnClick', true);
92+
93+
instance.pressTitle();
94+
95+
expect(instance.openBrowser).toHaveBeenCalled();
96+
expect(instance.markAsRead).toHaveBeenCalled();
97+
jest.runAllTimers();
98+
8199
});
82100

83101
it('Should render a notification component (PullRequest)', function () {
@@ -105,6 +123,9 @@ describe('Test for Notification Component', function () {
105123
expect(instance.openBrowser).toBeDefined();
106124
expect(instance.markAsRead).toBeDefined();
107125

126+
// Open Browser
127+
instance.openBrowser();
128+
108129
});
109130

110131
it('Should render a notification component (OtherType)', function () {

src/js/__tests__/components/repository.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ describe('Test for Repository Component', function () {
3434
item: false,
3535
getItem: function () {
3636
return this.item;
37+
},
38+
setItem: function (item) {
39+
this.item = item;
3740
}
3841
};
3942

src/js/components/notification.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var shell = remote.require('shell');
44

55
var Actions = require('../actions/actions');
66
var apiRequests = require('../utils/api-requests');
7+
var SettingsStore = require('../stores/settings');
78

89
var NotificationItem = React.createClass({
910

@@ -19,6 +20,16 @@ var NotificationItem = React.createClass({
1920
});
2021
},
2122

23+
pressTitle: function () {
24+
var markOnClick = SettingsStore.getSettings().markOnClick;
25+
if (markOnClick) {
26+
this.openBrowser();
27+
this.markAsRead();
28+
} else {
29+
this.openBrowser();
30+
}
31+
},
32+
2233
openBrowser: function () {
2334
var url = this.props.notification.subject.url.replace('api.github.com/repos', 'www.github.com');
2435
if (url.indexOf('/pulls/') != -1) {
@@ -67,7 +78,7 @@ var NotificationItem = React.createClass({
6778
return (
6879
<div className={this.state.isRead ? 'row notification read' : 'row notification'}>
6980
<div className='col-xs-1'><span className={typeIconClass} /></div>
70-
<div className='col-xs-10 subject' onClick={this.openBrowser}>
81+
<div className='col-xs-10 subject' onClick={this.pressTitle}>
7182
{this.props.notification.subject.title}
7283
</div>
7384
<div className='col-xs-1 check-wrapper'>

src/js/components/settings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var SettingsPage = React.createClass({
1313
participating: settings.participating,
1414
playSound: settings.playSound,
1515
showNotifications: settings.showNotifications,
16+
markOnClick: settings.markOnClick,
1617
openAtStartup: settings.openAtStartup
1718
};
1819
},
@@ -56,6 +57,16 @@ var SettingsPage = React.createClass({
5657
onChange={this.toggleSetting.bind(this, 'showNotifications')} />
5758
</div>
5859
</div>
60+
61+
<div className='row'>
62+
<div className='col-xs-8'>On Click, Mark as Read</div>
63+
<div className='col-xs-4'>
64+
<Toggle
65+
defaultChecked={this.state.markOnClick}
66+
onChange={this.toggleSetting.bind(this, 'markOnClick')} />
67+
</div>
68+
</div>
69+
5970
<div className='row'>
6071
<div className='col-xs-8'>Open at startup</div>
6172
<div className='col-xs-4'>

src/js/stores/settings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var SettingsStore = Reflux.createStore({
1414
participating: false,
1515
playSound: true,
1616
showNotifications: true,
17+
markOnClick: false,
1718
openAtStartup: false
1819
};
1920
}
@@ -34,6 +35,10 @@ var SettingsStore = Reflux.createStore({
3435
settings.showNotifications = true;
3536
}
3637

38+
if (typeof settings.markOnClick !== 'boolean') {
39+
settings.markOnClick = false;
40+
}
41+
3742
if (typeof settings.openAtStartup !== 'boolean') {
3843
settings.openAtStartup = false;
3944
}

src/less/style.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ input {
320320
.settings {
321321
background-color: @ThemePrimary;
322322
color: @White;
323-
padding: 20px;
323+
padding: 15px 20px;
324324

325325
.row {
326-
margin: 20px 10px;
326+
margin: 12px 10px;
327327

328328
.col-xs-4 {
329329
text-align: right;

0 commit comments

Comments
 (0)