Skip to content

Commit

Permalink
Add Offline component
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoaraujojunior committed Jan 3, 2017
1 parent 33f2a0f commit 82209c0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "presets": ["react", "es2015"] }
6 changes: 3 additions & 3 deletions app/components/Menu/Menu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Router } from 'react-router'

import Nav from 'components/Nav/Nav'
import NavMenu from 'components/NavMenu/NavMenu'
import LinksApp from 'components/LinksApp/LinksApp'


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

handleView() {
return (
<Nav>
<NavMenu>
<LinksApp
links={this.state.links}
/>
<span className="nav-item">
<a className="button" onClick={this.handleLogout}>Logout</a>
</span>
</Nav>
</NavMenu>
);
}

Expand Down
13 changes: 10 additions & 3 deletions app/components/Nav/Nav.js → app/components/NavMenu/NavMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

class Nav extends React.Component
import Offline from 'components/Offline/Offline'

class NavMenu extends React.Component
{
constructor(props, context) {
super(props, context);
Expand Down Expand Up @@ -33,6 +35,11 @@ class Nav extends React.Component
<div className="nav-left">
<a className="nav-item" href="../index.html">IClient</a>
</div>
<span className="nav-center nav-menu is-active">
<span className="nav-item">
<Offline />
</span>
</span>
<span className={ `nav-toggle ${this.state.toggleNavStatus}` } onClick={this.toggleNavStatus}>
<span></span>
<span></span>
Expand All @@ -47,9 +54,9 @@ class Nav extends React.Component
}
}

Nav.childContextTypes = {
NavMenu.childContextTypes = {
onClick: React.PropTypes.func
};

export default Nav;
export default NavMenu;

42 changes: 42 additions & 0 deletions app/components/Offline/Offline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';

class Offline extends React.Component
{
constructor(props, context) {
super(props, context);
this.updateNetworkStatus = this.updateNetworkStatus.bind(this);
this.state = {
networkStatus: {
display: 'none'
}
};
}

componentWillMount() {
this.updateNetworkStatus();
window.addEventListener('online', this.updateNetworkStatus, false);
window.addEventListener('offline', this.updateNetworkStatus, false);
}

updateNetworkStatus() {
if (navigator.onLine) {
this.setState({networkStatus: {display : 'none'}});
} else {
this.setState({networkStatus: {display : ''}});
}
}

render() {
return (
<a className="button is-danger is-disabled" style={this.state.networkStatus}>
<span className="icon">
<i className="fa fa-spinner"></i>
</span>
<span>Off Line</span>
</a>
);
}
}

export default Offline;

16 changes: 8 additions & 8 deletions tests/Nav.test.js → tests/NavMenu.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

describe('Test Nav', () => {
describe('Test NavMenu', () => {
const React = require('react');
const shallow = require('enzyme').shallow;
const Nav = require('components/Nav/Nav').default;
const NavMenu = require('components/NavMenu/NavMenu').default;

it('Nav should render child', (done) => {
it('NavMenu should render child', (done) => {

let component = shallow(
<Nav>
<NavMenu>
<directive>Child</directive>
</Nav>
</NavMenu>
);

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

let component = shallow(
<Nav />
<NavMenu />
);

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

let component = shallow(
<Nav />
<NavMenu />
);

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

let component = shallow(
<Nav />
<NavMenu />
);

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

0 comments on commit 82209c0

Please sign in to comment.