-
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
Open
codemcu
wants to merge
6
commits into
master
Choose a base branch
from
githubSearch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72daca3
buscador de usuarios por nombre en github
codemcu c7f8976
Merge branch 'master' into githubSearch
codemcu 4e7cd33
correcciones
codemcu 4c18cb0
try/catch
codemcu 4726964
Merge branch 'master' into githubSearch
codemcu dbf915c
feedback
codemcu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
body { | ||
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; | ||
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
(() => { | ||
|
||
const input = document.querySelector('input'); | ||
input.addEventListener('keyup', searchUser, false); | ||
const container = document.querySelector('.container'); | ||
|
||
async function searchUser(event) { | ||
|
||
try { | ||
if (event.code === 'Enter' && event.isTrusted) { | ||
|
||
if (!!input.value.trim()) { | ||
|
||
if (document.querySelector('ul') !== null) { | ||
document.querySelector('ul').remove(); | ||
} | ||
if (document.querySelector('p') !== null) { | ||
document.querySelector('p').remove(); | ||
} | ||
|
||
const text = input.value.trim(); | ||
|
||
const response = await callApi(`https://api.github.com/search/users?q=${text}+in%3Afullname&type=Users`); | ||
generateUserList(response); | ||
|
||
} else { | ||
const p = document.createElement('P'); | ||
container.appendChild(p); | ||
p.textContent = 'Please enter username'; | ||
return false; | ||
} | ||
} | ||
} catch (error) { | ||
console.log('searchUser', error); | ||
} | ||
|
||
} | ||
|
||
function ajax(url) { | ||
return new Promise((resolve, reject) => { | ||
fetch(url) | ||
.then(response => { | ||
if (response.status === 200) { | ||
resolve(response.json()) | ||
} else { | ||
reject(response.json()); | ||
} | ||
}) | ||
.catch(error => console.log('ajax', error)); | ||
}) | ||
} | ||
|
||
async function callApi(url) { | ||
try { | ||
return await ajax(url); | ||
} catch (error) { | ||
console.log('callApi', error); | ||
} | ||
} | ||
|
||
function generateUserList(data) { | ||
if (data.items && data.items.length) { | ||
const ul = document.createElement('UL'); | ||
container.appendChild(ul); | ||
|
||
const users = data.items; | ||
const urls = users.map(user => user.url); | ||
const request = urls.map(url => fetch(url).then(res => res.json())); | ||
|
||
Promise.all(request) | ||
.then(res => { | ||
res.forEach( item => { | ||
const div = makeTemplate(item); | ||
ul.insertAdjacentHTML('afterbegin', div); | ||
}); | ||
}) | ||
.catch(err => console.log(err)); | ||
} else { | ||
const p = document.createElement('P'); | ||
container.appendChild(p); | ||
p.textContent = 'Please enter a valid name'; | ||
return false; | ||
} | ||
|
||
} | ||
|
||
function makeTemplate(item) { | ||
const template = | ||
` | ||
<li>${item.login} | ||
<a href="${item.html_url}" target="_blank"> | ||
<img src="${item.avatar_url}"> | ||
</a> | ||
<div class="user-details"> | ||
<div>Score: | ||
<span></span> | ||
</div> | ||
<div> | ||
<span>Followers: ${item.followers}</span> | ||
</div> | ||
<div> | ||
<span>Followings: ${item.following}</span> | ||
</div> | ||
</div> | ||
</li> | ||
`; | ||
|
||
return template; | ||
} | ||
|
||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.