Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-co committed Jan 4, 2024
1 parent 468eb68 commit 39f5634
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
12 changes: 4 additions & 8 deletions React/test-git/src/contexts/GitReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ const gitReducer = (state, action) => {
...state,
users: action.payload
}
case 'GET_USER':
case 'GET_USER_REPOS':
return {
...state,
user: action.payload
}
case 'GET_REPOS':
return {
...state,
repos: action.payload
}
user: action.payload.user,
repos: action.payload.repos
}
case 'CLEAR':
return {
...state,
Expand Down
22 changes: 8 additions & 14 deletions React/test-git/src/contexts/GtiAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ const axiosURL = axios.create({
})

export const getUsers = async (text) => {
const res = axiosURL.get('search/users?q=' + text)
const res = axiosURL.get('search/users?q=' + text)
return res.data.items
}

export const getUser = async (text) => {
const res = await fetch(GITHUB_URL + 'users/' + text)
const data = await res.json()
return data
}

export const getRepos = async (text) => {
const params = new URLSearchParams({

})
const res = await fetch(GITHUB_URL + 'users/' + text + '/repos')
const data = await res.json()
return data
export const getUserRepos = async (text) => {
const [user, repos] = await Promise.all([
axiosURL.get(`users/${text}`),
axiosURL.get(`users/${text}/repos`)
])
console.log(user, repos)
return { user: user.data, repos: repos.data }
}
15 changes: 5 additions & 10 deletions React/test-git/src/pages/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ import { Link, useParams } from 'react-router-dom'
import { FaUserFriends, FaUsers, FaCodepen, FaStore } from 'react-icons/fa'
import { Repo } from '../components/repos/Repo'
import GitContext from '../contexts/GitContext'
import { getUser, getRepos } from '../contexts/GtiAction'
import { getUserRepos } from '../contexts/GtiAction'

export const User = () => {
const { dispatch, user, repos } = useContext(GitContext)
const params = useParams()

useEffect(() => {
useEffect(() => {
const getUserAndRepo = async () => {
dispatch({
type: 'GET_USER',
payload: await getUser(params.login)
})

dispatch({
type: 'GET_REPOS',
payload: await getRepos(params.login)
})
type: 'GET_USER_REPOS',
payload: await getUserRepos(params.login)
})
}

getUserAndRepo()
Expand Down

0 comments on commit 39f5634

Please sign in to comment.