Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-co committed Jan 2, 2024
1 parent d041f76 commit 468eb68
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
29 changes: 29 additions & 0 deletions React/test-git/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions React/test-git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.3",
"daisyui": "^4.4.14",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
8 changes: 3 additions & 5 deletions React/test-git/src/components/users/UserSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ export const UserSearch = () => {
const [text, setText] = useState('')
const { dispatch, users } = useContext(GitContext)
const handleSubmit = async (e) => {
e.preventDefault()
console.log(getUsers(text))
await dispatch({
e.preventDefault()
dispatch({
type: 'GET_USERS',
payload: await getUsers(text)
})
console.log(users)
})
}

const handleChange = (e) => {
Expand Down
13 changes: 8 additions & 5 deletions React/test-git/src/contexts/GtiAction.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import axios from 'axios'

const GITHUB_URL = 'https://github.com/gitapi/'
const axiosURL = axios.create({
baseURL: GITHUB_URL,
headers: {}
})

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

export const getUser = async (text) => {
Expand Down
24 changes: 14 additions & 10 deletions React/test-git/src/pages/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ 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 { getUser, getRepos } from '../contexts/GtiAction'

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

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

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

getUserAndRepo()
}, [])

const {
Expand Down

0 comments on commit 468eb68

Please sign in to comment.