2017-09-17 21:16:19 +00:00
|
|
|
import { provideState, update } from 'freactal'
|
|
|
|
import { fetchUserRepos } from './githubApi'
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
export default serverState =>
|
|
|
|
provideState({
|
|
|
|
initialState: () => ({
|
|
|
|
...serverState,
|
|
|
|
ajaxStatus: false
|
|
|
|
}),
|
2017-09-17 21:16:19 +00:00
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
effects: {
|
|
|
|
setAjaxLoader: update((state, ajaxStatus) => ({ ajaxStatus })),
|
2017-09-17 21:16:19 +00:00
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
fetchGithubReposList: (effects, username, page) =>
|
|
|
|
effects
|
|
|
|
.setAjaxLoader(true)
|
|
|
|
.then(() => fetchUserRepos(username, page))
|
|
|
|
.then(repos => effects.setAjaxLoader(false).then(() => repos))
|
|
|
|
.then(repos => state => ({
|
|
|
|
...state,
|
|
|
|
githubReposList: {
|
|
|
|
username,
|
|
|
|
page,
|
|
|
|
repos: state.githubReposList.repos.concat(repos)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
})
|