Skip to content

Commit 82209c0

Browse files
committed
Add Offline component
1 parent 33f2a0f commit 82209c0

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "presets": ["react", "es2015"] }

app/components/Menu/Menu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Router } from 'react-router'
33

4-
import Nav from 'components/Nav/Nav'
4+
import NavMenu from 'components/NavMenu/NavMenu'
55
import LinksApp from 'components/LinksApp/LinksApp'
66

77

@@ -26,14 +26,14 @@ class Menu extends React.Component{
2626

2727
handleView() {
2828
return (
29-
<Nav>
29+
<NavMenu>
3030
<LinksApp
3131
links={this.state.links}
3232
/>
3333
<span className="nav-item">
3434
<a className="button" onClick={this.handleLogout}>Logout</a>
3535
</span>
36-
</Nav>
36+
</NavMenu>
3737
);
3838
}
3939

app/components/Nav/Nav.js renamed to app/components/NavMenu/NavMenu.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22

3-
class Nav extends React.Component
3+
import Offline from 'components/Offline/Offline'
4+
5+
class NavMenu extends React.Component
46
{
57
constructor(props, context) {
68
super(props, context);
@@ -33,6 +35,11 @@ class Nav extends React.Component
3335
<div className="nav-left">
3436
<a className="nav-item" href="../index.html">IClient</a>
3537
</div>
38+
<span className="nav-center nav-menu is-active">
39+
<span className="nav-item">
40+
<Offline />
41+
</span>
42+
</span>
3643
<span className={ `nav-toggle ${this.state.toggleNavStatus}` } onClick={this.toggleNavStatus}>
3744
<span></span>
3845
<span></span>
@@ -47,9 +54,9 @@ class Nav extends React.Component
4754
}
4855
}
4956

50-
Nav.childContextTypes = {
57+
NavMenu.childContextTypes = {
5158
onClick: React.PropTypes.func
5259
};
5360

54-
export default Nav;
61+
export default NavMenu;
5562

app/components/Offline/Offline.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
3+
class Offline extends React.Component
4+
{
5+
constructor(props, context) {
6+
super(props, context);
7+
this.updateNetworkStatus = this.updateNetworkStatus.bind(this);
8+
this.state = {
9+
networkStatus: {
10+
display: 'none'
11+
}
12+
};
13+
}
14+
15+
componentWillMount() {
16+
this.updateNetworkStatus();
17+
window.addEventListener('online', this.updateNetworkStatus, false);
18+
window.addEventListener('offline', this.updateNetworkStatus, false);
19+
}
20+
21+
updateNetworkStatus() {
22+
if (navigator.onLine) {
23+
this.setState({networkStatus: {display : 'none'}});
24+
} else {
25+
this.setState({networkStatus: {display : ''}});
26+
}
27+
}
28+
29+
render() {
30+
return (
31+
<a className="button is-danger is-disabled" style={this.state.networkStatus}>
32+
<span className="icon">
33+
<i className="fa fa-spinner"></i>
34+
</span>
35+
<span>Off Line</span>
36+
</a>
37+
);
38+
}
39+
}
40+
41+
export default Offline;
42+

tests/Nav.test.js renamed to tests/NavMenu.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
describe('Test Nav', () => {
2+
describe('Test NavMenu', () => {
33
const React = require('react');
44
const shallow = require('enzyme').shallow;
5-
const Nav = require('components/Nav/Nav').default;
5+
const NavMenu = require('components/NavMenu/NavMenu').default;
66

7-
it('Nav should render child', (done) => {
7+
it('NavMenu should render child', (done) => {
88

99
let component = shallow(
10-
<Nav>
10+
<NavMenu>
1111
<directive>Child</directive>
12-
</Nav>
12+
</NavMenu>
1313
);
1414

1515
expect(component.find('directive').text()).toEqual('Child');
@@ -20,7 +20,7 @@ describe('Test Nav', () => {
2020
it('toggleNavStatus function should change toggleNavStatus state from is-active to empty', (done) => {
2121

2222
let component = shallow(
23-
<Nav />
23+
<NavMenu />
2424
);
2525

2626
component.instance().setState({ toggleNavStatus: 'is-active' });
@@ -34,7 +34,7 @@ describe('Test Nav', () => {
3434
it('toggleNavStatus function should change toggleNavStatus state from empty to is-active', (done) => {
3535

3636
let component = shallow(
37-
<Nav />
37+
<NavMenu />
3838
);
3939

4040
expect(component.state().toggleNavStatus).toEqual('');
@@ -47,7 +47,7 @@ describe('Test Nav', () => {
4747
it('hide should change toggleNavStatus state to empty', (done) => {
4848

4949
let component = shallow(
50-
<Nav />
50+
<NavMenu />
5151
);
5252

5353
component.instance().setState({ toggleNavStatus: 'whatever'} );

0 commit comments

Comments
 (0)