-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
33 lines (29 loc) · 1.26 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as types from './types'
// SEARCH USER
export const searchUser = (querySearch, pageResult) => (dispatch) =>{
dispatch({ type: types.SEARCH_USERS })
fetch(`https://api.github.com/search/users?q=${querySearch}&per_page=${20}&page=${pageResult}`)
.then(rsp=>rsp.json())
.then(rsp=>{
dispatch({ type: types.SEARCH_USERS_SUCCESS, payload: { results: rsp.items, page: pageResult } })
},
error=>{
console.log(error)
dispatch({ type: types.SEARCH_USERS_FAIL, payload: { error: 'Ocurrio un problema al intentar realizar la búsqueda' } })
})
}
export const emptyUser = () => ({ type: types.USERS_EMPTY })
// SEARC REPO
export const searchRepo = (querySearch, pageResult) => (dispatch) =>{
dispatch({ type: types.SEARCH_REPOS })
fetch(`https://api.github.com/search/repositories?q=${querySearch}&per_page=${20}&page=${pageResult}`)
.then(rsp=>rsp.json())
.then(rsp=>{
dispatch({ type: types.SEARCH_REPOS_SUCCESS, payload: { results: rsp.items, page: pageResult } })
},
error=>{
console.log(error)
dispatch({ type: types.SEARCH_USERS_FAIL, payload: { error: 'Ocurrio un problema al intentar realizar la búsqueda' } })
})
}
export const emptyRepo = () => ({ type: types.REPOS_EMPTY })