Skip to content

Commit 34169dc

Browse files
authored
Merge pull request #216 from manosim/offline-alert
[209] Check Internet Connection
2 parents 3df1644 + a3aafff commit 34169dc

File tree

6 files changed

+142
-13
lines changed

6 files changed

+142
-13
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gitify [![travis][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url] [![slack][slack-image]][slack-url]
22

3-
> If you are looking for the mobile version - [ekonstantinidis/gitify-mobile](https://github.com/ekonstantinidis/gitify-mobile/).
3+
> If you are looking for the mobile version - [manosim/gitify-mobile](https://github.com/manosim/gitify-mobile/).
44
55
![Gitify](images/press.png)
66

@@ -11,11 +11,11 @@
1111
1212
> Cheers,
1313
14-
> Manos (ekonstantinidis)
14+
> Manos
1515
1616

1717
### Download
18-
You can download Gitify for **free** from either the website [www.gitify.io](http://www.gitify.io/) or from the GitHub repository [releases](https://github.com/ekonstantinidis/gitify/releases) page.
18+
You can download Gitify for **free** from either the website [www.gitify.io](http://www.gitify.io/) or from the GitHub repository [releases](https://github.com/manosim/gitify/releases) page.
1919

2020
You can also install Gitify via [Homebrew Cask](http://caskroom.io/)
2121

@@ -90,9 +90,9 @@ There are 2 linters for `js` & `scss` and unit tests with `mocha`.
9090
Gitify is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.
9191

9292

93-
[travis-image]: https://travis-ci.org/ekonstantinidis/gitify.svg?branch=master
94-
[travis-url]: https://travis-ci.org/ekonstantinidis/gitify
95-
[codecov-image]: https://codecov.io/gh/ekonstantinidis/gitify/branch/master/graph/badge.svg
96-
[codecov-url]: https://codecov.io/gh/ekonstantinidis/gitify
93+
[travis-image]: https://travis-ci.org/manosim/gitify.svg?branch=master
94+
[travis-url]: https://travis-ci.org/manosim/gitify
95+
[codecov-image]: https://codecov.io/gh/manosim/gitify/branch/master/graph/badge.svg
96+
[codecov-url]: https://codecov.io/gh/manosim/gitify
9797
[slack-image]: https://img.shields.io/badge/slack-atomio/gitify-e01563.svg
9898
[slack-url]: https://atomio.slack.com/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'; // eslint-disable-line no-unused-vars
2+
import { expect } from 'chai';
3+
import { shallow } from 'enzyme';
4+
import NetworkStatus from '../../components/network-status';
5+
6+
function setup() {
7+
const props = {};
8+
const wrapper = shallow(<NetworkStatus {...props} />);
9+
10+
return {
11+
props: props,
12+
wrapper: wrapper,
13+
};
14+
};
15+
16+
describe('components/network-status.js', function () {
17+
18+
it('should render itself & its children', function () {
19+
20+
const { wrapper } = setup();
21+
22+
expect(wrapper).to.exist;
23+
expect(wrapper.find('.alert').text()).to.equal('Couldn\'t establish an internet connection.');
24+
25+
});
26+
27+
});

src/js/__tests__/containers/app.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'; // eslint-disable-line no-unused-vars
22
import { expect } from 'chai';
3-
import { shallow } from 'enzyme';
4-
import App from '../../containers/app';
3+
import { shallow, mount } from 'enzyme';
4+
import { App } from '../../containers/app';
55

6-
function setup() {
6+
function setupShallow() {
77
const props = {
88
location: '/home'
99
};
@@ -15,11 +15,24 @@ function setup() {
1515
};
1616
};
1717

18+
function setupMount() {
19+
const props = {
20+
location: '/home'
21+
};
22+
const wrapper = mount(<App {...props} />);
23+
24+
return {
25+
props: props,
26+
wrapper: wrapper,
27+
};
28+
};
29+
30+
1831
describe('containers/app.js', function () {
1932

2033
it('should render itself & its children', function () {
2134

22-
const { wrapper } = setup();
35+
const { wrapper } = setupShallow();
2336

2437
expect(wrapper).to.exist;
2538
expect(wrapper.state().showSearch).to.be.false;
@@ -28,4 +41,14 @@ describe('containers/app.js', function () {
2841
expect(wrapper.state().showSearch).to.be.true;
2942
});
3043

44+
it('should mount itself & its children', function () {
45+
46+
const { wrapper } = setupMount();
47+
48+
expect(wrapper).to.exist;
49+
50+
wrapper.instance().handleNetworkStatus();
51+
expect(wrapper.state().networkConnected).to.be.false;
52+
});
53+
3154
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
export default class NetworkStatus extends React.Component {
4+
render() {
5+
return (
6+
<div className="network-status">
7+
<img className="img-fluid logo" src="images/gitify-logo-outline-dark.png" />
8+
<h4>No Internet Connection</h4>
9+
<div className="alert alert-danger">Couldn't establish an internet connection.</div>
10+
</div>
11+
);
12+
}
13+
};

src/js/containers/app.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
11
import React from 'react';
2+
import { connect } from 'react-redux';
23

4+
import { fetchNotifications } from '../actions';
35
import Navigation from '../components/navigation';
6+
import NetworkStatus from '../components/network-status';
47
import SearchBar from '../components/search';
58

6-
export default class App extends React.Component {
9+
export class App extends React.Component {
710
constructor(props) {
811
super(props);
912

1013
this.state = {
11-
showSearch: false
14+
showSearch: false,
15+
networkConnected: navigator.onLine
1216
};
1317
}
1418

19+
componentDidMount() {
20+
const self = this;
21+
window.addEventListener('offline', function(e) { self.handleNetworkStatus(); });
22+
window.addEventListener('online', function(e) { self.handleNetworkStatus(); });
23+
}
24+
25+
componentWillUnmount() {
26+
window.removeEventListener('offline', this.handleNetworkStatus);
27+
window.removeEventListener('online', this.handleNetworkStatus);
28+
}
29+
1530
toggleSearch() {
1631
this.setState({
1732
showSearch: !this.state.showSearch
1833
});
1934
}
2035

36+
handleNetworkStatus() {
37+
if (navigator.onLine) {
38+
this.setState({
39+
networkConnected: true
40+
});
41+
this.props.fetchNotifications();
42+
} else {
43+
this.setState({
44+
networkConnected: false
45+
});
46+
}
47+
}
48+
2149
render() {
50+
if (!this.state.networkConnected) {
51+
return <NetworkStatus />;
52+
}
53+
2254
return (
2355
<div>
2456
<Navigation
@@ -31,3 +63,5 @@ export default class App extends React.Component {
3163
);
3264
};
3365
};
66+
67+
export default connect(null, { fetchNotifications })(App);

src/scss/app.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,35 @@ input {
524524
}
525525

526526
/* @end Component / Search */
527+
528+
529+
/* @group Network Status */
530+
531+
.network-status {
532+
position: absolute;
533+
top: 0;
534+
right: 0;
535+
bottom: 0;
536+
left: 0;
537+
background-color: $gray-lighter;
538+
padding: 3rem 2rem;
539+
overflow: auto;
540+
541+
.logo {
542+
margin: 0 auto 20px;
543+
max-width: 115px;
544+
}
545+
546+
h4 {
547+
margin-bottom: 1.5rem;
548+
text-align: center;
549+
}
550+
551+
.emoji {
552+
margin: 20px 0;
553+
text-align: center;
554+
font-size: 55px;
555+
}
556+
}
557+
558+
/* @end Network Status */

0 commit comments

Comments
 (0)