-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change loading indicator UI/UX to rely on fetching state
In the previous implementation, show a loading indicator infinitely when API server response has no items. So, I improve this.
- Loading branch information
Showing
11 changed files
with
119 additions
and
6 deletions.
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 |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
} | ||
} | ||
|
||
.HackerNewsList__noti { | ||
text-align: center; | ||
} | ||
|
||
.HackerNewsList__item { | ||
margin: 30px 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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { connect } from 'react-redux'; | ||
|
||
import HackerNewsList from 'components/HackerNewsList'; | ||
import { getFeeds } from 'store/selectors'; | ||
import { getFeeds, getIsFetching } from 'store/selectors'; | ||
|
||
const mapStateToProps = (state, props) => ({ | ||
feeds: getFeeds(state, props), | ||
isFetching: getIsFetching(state), | ||
}); | ||
|
||
export default connect(mapStateToProps)(HackerNewsList); |
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,62 @@ | ||
import * as ACTIONS from 'store/actionTypes'; | ||
import isFetching from 'store/isFetching'; | ||
|
||
describe('isFetching reducer', () => { | ||
it('should return the initial state', () => { | ||
expect(isFetching(undefined, {})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_COMMENTS_FETCH_REQUEST', () => { | ||
expect(isFetching(false, { | ||
type: ACTIONS.HACKER_COMMENTS_FETCH_REQUEST, | ||
})).toBe(true); | ||
}); | ||
|
||
it('should handle HACKER_COMMENTS_FETCH_SUCCESS', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_COMMENTS_FETCH_SUCCESS, | ||
})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_COMMENTS_FETCH_FAILURE', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_COMMENTS_FETCH_FAILURE, | ||
})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_NEWS_FETCH_REQUEST', () => { | ||
expect(isFetching(false, { | ||
type: ACTIONS.HACKER_NEWS_FETCH_REQUEST, | ||
})).toBe(true); | ||
}); | ||
|
||
it('should handle HACKER_NEWS_FETCH_SUCCESS', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_NEWS_FETCH_SUCCESS, | ||
})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_NEWS_FETCH_FAILURE', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_NEWS_FETCH_FAILURE, | ||
})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_USER_FETCH_REQUEST', () => { | ||
expect(isFetching(false, { | ||
type: ACTIONS.HACKER_USER_FETCH_REQUEST, | ||
})).toBe(true); | ||
}); | ||
|
||
it('should handle HACKER_USER_FETCH_SUCCESS', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_USER_FETCH_SUCCESS, | ||
})).toBe(false); | ||
}); | ||
|
||
it('should handle HACKER_USER_FETCH_FAILURE', () => { | ||
expect(isFetching(true, { | ||
type: ACTIONS.HACKER_USER_FETCH_FAILURE, | ||
})).toBe(false); | ||
}); | ||
}); |
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,21 @@ | ||
import * as ACTIONS from '../actionTypes'; | ||
|
||
function itemsReducer(state = false, action) { | ||
switch (action.type) { | ||
case ACTIONS.HACKER_COMMENTS_FETCH_REQUEST: | ||
case ACTIONS.HACKER_NEWS_FETCH_REQUEST: | ||
case ACTIONS.HACKER_USER_FETCH_REQUEST: | ||
return true; | ||
case ACTIONS.HACKER_COMMENTS_FETCH_SUCCESS: | ||
case ACTIONS.HACKER_COMMENTS_FETCH_FAILURE: | ||
case ACTIONS.HACKER_NEWS_FETCH_SUCCESS: | ||
case ACTIONS.HACKER_NEWS_FETCH_FAILURE: | ||
case ACTIONS.HACKER_USER_FETCH_SUCCESS: | ||
case ACTIONS.HACKER_USER_FETCH_FAILURE: | ||
return false; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default itemsReducer; |
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