-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buscador de usuarios por nombre en github #41
base: master
Are you sure you want to change the base?
Changes from 1 commit
72daca3
c7f8976
4e7cd33
4c18cb0
4726964
dbf915c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* https://color.adobe.com/es/Copy-of-Pastels-color-theme-11580203/ | ||
background: #F8B195" | ||
background: #F67280" | ||
background: #C06C84" | ||
background: #6C5B7B" | ||
background: #355C7D"*/ | ||
|
||
body { | ||
/*background-color: #F8B195;*/ | ||
font-family: 'Roboto', sans-serif; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} | ||
|
||
.container { | ||
max-width: 1200px; | ||
margin: auto; | ||
} | ||
|
||
.logo { | ||
max-width: 2.5rem; | ||
vertical-align: sub; | ||
} | ||
|
||
input { | ||
margin: 0 auto 3.125rem; | ||
display: block; | ||
font-size: 1.875rem; | ||
padding: 0.3125rem 0.9375rem; | ||
border: 0.125rem solid #355C7D; | ||
} | ||
|
||
p { | ||
text-align: left; | ||
margin: 0; | ||
} | ||
|
||
ul { | ||
width: 620px; | ||
margin: 0 auto 0; | ||
list-style-type: none; | ||
/*background-color: #355C7D;*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ El código comentado... sobra |
||
padding: 1.25rem 1.25rem 0.3125rem 1.25rem; | ||
color: #fff; | ||
} | ||
|
||
ul li { | ||
margin: 0.45rem 0 1.75rem 0; | ||
position: relative; | ||
padding: 20px 4.0625rem 20px 110px; | ||
font-size: 1.25rem; | ||
background-color: #355C7D; | ||
} | ||
|
||
ul li a { | ||
display: block; | ||
} | ||
|
||
ul li img { | ||
width: 3.5rem; | ||
height: 3.5rem; | ||
position: absolute; | ||
left: 4%; | ||
top: 50%; | ||
transform: translate(0%, -50%); | ||
border-radius: 50%; | ||
border: 0.125rem solid #F8B195; | ||
padding: 0.125rem; | ||
} | ||
|
||
div .user-details { | ||
display: table; | ||
width: 100%; | ||
margin-top: 0.3125rem; | ||
} | ||
|
||
div .user-details div { | ||
display: table-cell; | ||
width: 35%; | ||
font-size: 1rem; | ||
} | ||
|
||
.p-username { | ||
font-weight: 700; | ||
margin-bottom: 0.3125rem; | ||
} | ||
|
||
span { | ||
font-weight: 300; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="es"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"/> | ||
<link rel="stylesheet" href="css/style.css" type="text/css"/> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h1>Search by username <img class="logo" src="img/github.png"></h1> | ||
|
||
<input type="text" id="input" placeholder="Eric Elliott"/> | ||
</div> | ||
|
||
<script type="text/javascript" src="js/main.js"></script> | ||
</body> | ||
</html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
(function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. podría ser arrow... |
||
|
||
const input = document.querySelector('input'); | ||
input.addEventListener('keyup', searchUser, false); | ||
const container = document.querySelector('.container'); | ||
|
||
function searchUser($event) { | ||
|
||
if ($event.code === 'Enter' && $event.isTrusted) { | ||
|
||
if (input.value.trim() === '') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No necesitas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const p = document.createElement('P'); | ||
container.appendChild(p); | ||
p.textContent = 'Please enter username'; | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
||
} else { | ||
|
||
if (document.querySelector('ul') !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mete este selector en una variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
document.querySelector('ul').remove(); | ||
} | ||
|
||
const text = input.value.trim(); | ||
|
||
loadAjax(`https://api.github.com/search/users?q=${text}+in%3Afullname&type=Users`) | ||
.then(getNetwork) | ||
.catch(error => console.log(error)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gestiona el error de forma visual también There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. he metido |
||
|
||
} | ||
} | ||
} | ||
|
||
function loadAjax(url) { | ||
return new Promise((resolve, reject) => { | ||
fetch(url) | ||
.then(json => json.json()) | ||
.then(resolve) | ||
.catch(reject); | ||
}) | ||
} | ||
|
||
function getNetwork(urlNetwork) { | ||
const users = urlNetwork.items; | ||
|
||
if (users && users.length) { | ||
|
||
users.forEach(function (item) { | ||
|
||
const followers = new Promise( (resolve, reject) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nadie gestiona los errores... 🤦♂️ |
||
loadAjax(`https://api.github.com/users/${item.login}/followers`) | ||
.then(resolve) | ||
}) | ||
|
||
const followings = new Promise( (resolve, reject) => { | ||
loadAjax(`https://api.github.com/users/${item.login}/following`) | ||
.then(resolve) | ||
}) | ||
|
||
createContainerUser(item, followers, followings); | ||
}); | ||
} else { | ||
feedBackMessage('No users found'); | ||
} | ||
} | ||
|
||
function createContainerUser(item, followers, followings) { | ||
const ul = document.createElement('UL'); | ||
const li = document.createElement('LI'); | ||
const img = document.createElement('IMG'); | ||
const div = document.createElement('DIV'); | ||
div.setAttribute('class', 'user-details'); | ||
|
||
const divScore = document.createElement('DIV'); | ||
|
||
li.appendChild(document.createTextNode(item.login)); | ||
|
||
divScore.innerHTML = `Score: <span>${item.score.toFixed(2)}</span>`; | ||
|
||
img.setAttribute('src', item.avatar_url); | ||
|
||
ul.appendChild(li); | ||
li.appendChild(img); | ||
li.appendChild(div); | ||
div.appendChild(divScore); | ||
container.appendChild(ul); | ||
|
||
getFollowers(followers, div); | ||
getFollowings(followings, div); | ||
} | ||
|
||
function getFollowers (followers, div) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
followers.then( res => { | ||
const divFollower = document.createElement('DIV'); | ||
divFollower.innerHTML = `Followers: <span>${res.length}</span>`; | ||
div.appendChild(divFollower); | ||
}); | ||
} | ||
|
||
function getFollowings(followings, div) { | ||
followings.then( res => { | ||
const divFollowing = document.createElement('DIV'); | ||
divFollowing.innerHTML = `Followings: <span>${res.length}</span>`; | ||
div.appendChild(divFollowing); | ||
}); | ||
} | ||
|
||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ El código comentado... sobra