This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from LiskHQ/494-global-loading-bar
Migrate global loading bar to React - Closes #494
- Loading branch information
Showing
14 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import actionTypes from '../constants/actions'; | ||
|
||
/** | ||
* An action to dispatch loadingStarted | ||
* | ||
*/ | ||
export const loadingStarted = data => ({ | ||
data, | ||
type: actionTypes.loadingStarted, | ||
}); | ||
|
||
/** | ||
* An action to dispatch loadingFinished | ||
* | ||
*/ | ||
export const loadingFinished = data => ({ | ||
data, | ||
type: actionTypes.loadingFinished, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect } from 'chai'; | ||
import actionTypes from '../constants/actions'; | ||
import { | ||
loadingStarted, | ||
loadingFinished, | ||
} from './loading'; | ||
|
||
|
||
describe('actions: loading', () => { | ||
describe('loadingStarted', () => { | ||
it('should create an action to show loading bar', () => { | ||
const data = 'test'; | ||
|
||
const expectedAction = { | ||
data, | ||
type: actionTypes.loadingStarted, | ||
}; | ||
expect(loadingStarted(data)).to.be.deep.equal(expectedAction); | ||
}); | ||
}); | ||
|
||
describe('loadingFinished', () => { | ||
it('should create an action to hide loading bar', () => { | ||
const data = 'test'; | ||
|
||
const expectedAction = { | ||
data, | ||
type: actionTypes.loadingFinished, | ||
}; | ||
expect(loadingFinished(data)).to.be.deep.equal(expectedAction); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
import { connect } from 'react-redux'; | ||
import LoadingBar from './loadingBar'; | ||
|
||
const mapStateToProps = state => ({ | ||
loading: state.loading, | ||
}); | ||
|
||
export default connect(mapStateToProps)(LoadingBar); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import LoadingBar from './'; | ||
import store from '../../store'; | ||
|
||
|
||
describe('LoadingBar Container', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<Provider store={store}><LoadingBar /></Provider>); | ||
}); | ||
|
||
it('should render Send', () => { | ||
expect(wrapper.find('LoadingBar')).to.have.lengthOf(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.fixedAtTop { | ||
position: fixed; | ||
top: -11px; | ||
right: 0; | ||
width: 100vw; | ||
z-index: 201; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import ProgressBar from 'react-toolbox/lib/progress_bar'; | ||
import styles from './loadingBar.css'; | ||
|
||
const LoadingBar = props => ( | ||
<div className={styles.fixedAtTop}> | ||
{props.loading && props.loading.length ? | ||
<ProgressBar type="linear" mode="indeterminate" /> : | ||
null | ||
} | ||
</div> | ||
); | ||
|
||
export default LoadingBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import LoadingBar from './loadingBar'; | ||
|
||
|
||
describe('LoadingBar Container', () => { | ||
it('should show ProgresBar if props.loading.length is not 0', () => { | ||
const wrapper = mount(<LoadingBar loading={['test']} />); | ||
expect(wrapper.find('ProgressBar')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('should not show ProgresBar if props.loading.length is 0', () => { | ||
const wrapper = mount(<LoadingBar loading={[]} />); | ||
expect(wrapper.find('ProgressBar')).to.have.lengthOf(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import actionTypes from '../../constants/actions'; | ||
|
||
/** | ||
* | ||
* @param {Array} state | ||
* @param {Object} action | ||
*/ | ||
const dialog = (state = [], action) => { | ||
switch (action.type) { | ||
case actionTypes.loadingStarted: | ||
return [...state, action.data]; | ||
case actionTypes.loadingFinished: | ||
return state.filter(item => item !== action.data); | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default dialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import loading from './loading'; | ||
import actionTypes from '../../constants/actions'; | ||
|
||
|
||
chai.use(sinonChai); | ||
|
||
describe('Reducer: loading(state, action)', () => { | ||
let state; | ||
|
||
beforeEach(() => { | ||
state = ['test1', 'test2']; | ||
}); | ||
|
||
it('should return loading array with the new loading if action.type = actionTypes.loadingStarted', () => { | ||
const action = { | ||
type: actionTypes.loadingStarted, | ||
data: 'test3', | ||
}; | ||
const changedState = loading(state, action); | ||
expect(changedState).to.deep.equal([...state, action.data]); | ||
}); | ||
|
||
it('should return loading array without action.data if action.type = actionTypes.loadingFinished', () => { | ||
const action = { | ||
type: actionTypes.loadingFinished, | ||
data: 'test1', | ||
}; | ||
const changedState = loading(state, action); | ||
expect(changedState).to.deep.equal(['test2']); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { loadingStarted, loadingFinished } from '../../utils/loading'; | ||
|
||
/* eslint-disable */ | ||
export const requestToActivePeer = (activePeer, path, urlParams) => | ||
new Promise((resolve, reject) => { | ||
loadingStarted(path); | ||
activePeer.sendRequest(path, urlParams, (data) => { | ||
if (data.success) { | ||
resolve(data); | ||
} else { | ||
reject(data); | ||
} | ||
loadingFinished(path); | ||
}); | ||
}); | ||
/* eslint-enable */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { loadingStarted as loadingStartedAction, loadingFinished as loadingFinishedAction } from '../actions/loading'; | ||
import store from '../store'; | ||
|
||
|
||
export const loadingStarted = data => store.dispatch(loadingStartedAction(data)); | ||
|
||
export const loadingFinished = data => store.dispatch(loadingFinishedAction(data)); |