-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a2120ee
Showing
11 changed files
with
398 additions
and
0 deletions.
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,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"cadudias" | ||
] | ||
} |
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,3 @@ | ||
# projeto-inicial-fetch-github-api | ||
|
||
Repositório contendo os arquivos iniciais do projeto de Fetch e GitHub API |
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,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="pt-br"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>GitHub API - buscando usuários com fetch</title> | ||
|
||
<link rel="stylesheet" href="src/css/reset.css"> | ||
<link rel="stylesheet" href="src/css/styles.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css"> | ||
</head> | ||
|
||
<body> | ||
<main> | ||
<i class="devicon-github-original"></i> | ||
|
||
<section class="container"> | ||
<header> | ||
<h2>Buscar Usuário</h2> | ||
<input type="text" id="input-search" placeholder="Digite o nome do usuário no GitHub"> | ||
<input type="button" value="Buscar" id="btn-search"> | ||
</header> | ||
|
||
<div class="profile-data"></div> | ||
</section> | ||
</main> | ||
|
||
<script type="module" src="src/scripts/index.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,18 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
a{ | ||
text-decoration: none; | ||
color: var(--cor-branca); | ||
} | ||
|
||
ul{ | ||
list-style: none; | ||
} | ||
|
||
img{ | ||
max-width: 100%; | ||
} |
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,195 @@ | ||
@import url("https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@400;700&display=swap"); | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
font-weight: 300; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
} | ||
|
||
body { | ||
background-color:#24292e; | ||
font-family: "Kumbh Sans", sans-serif; | ||
text-align: center; | ||
padding-bottom: 100px; | ||
} | ||
|
||
main { | ||
display: flex; | ||
justify-content: center; | ||
flex-direction: column; | ||
padding: 50px 0 0; | ||
} | ||
|
||
.devicon-github-original{ | ||
font-size: 60px; | ||
margin-bottom: 30px; | ||
color: #FFFFFF; | ||
} | ||
|
||
.section{ | ||
padding: 70px 0; | ||
} | ||
|
||
.container { | ||
width: 60%; /* se for uma tela menor que 980px vai se adaptar a 70% */ | ||
max-width: 960px; /* quando chegar em 980px para de aumentar */ | ||
box-shadow: rgba(0, 0, 0, 0.3) 0px 25px 50px -12px; | ||
background-color: #fff; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
border-radius: 30px; | ||
padding: 30px; | ||
margin: 0 auto; | ||
} | ||
|
||
.container header { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
padding: 30px 0; | ||
} | ||
|
||
.container header h2 { | ||
font-size: 20px; | ||
font-weight: 700; | ||
margin-bottom: 30px; | ||
} | ||
|
||
.container header #input-search { | ||
width: 400px; | ||
font-size: 17px; | ||
margin: 0 auto; | ||
padding: 10px; | ||
border-radius: 7px; | ||
border: 1px solid grey; | ||
} | ||
|
||
.container header #btn-search { | ||
width: 200px; | ||
font-size: 17px; | ||
margin: 20px auto 0; | ||
padding: 10px; | ||
border-radius: 7px; | ||
cursor: pointer; | ||
border: 1px solid grey; | ||
} | ||
|
||
.container header #btn-search:hover { | ||
background-color: hotpink; | ||
color: #ffffff; | ||
border-color: #ffffff; | ||
} | ||
|
||
.container .profile-data{ | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 40px; | ||
} | ||
|
||
.container .profile-data .info { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
} | ||
|
||
.container .profile-data .info .data{ | ||
padding: 40px; | ||
width: 50%; | ||
} | ||
|
||
.container .profile-data .info img{ | ||
width: 50%; | ||
border-radius: 50%; | ||
border: 10px solid hotpink; | ||
} | ||
|
||
.container .profile-data .info h1{ | ||
font-size: 20px; | ||
margin-bottom: 20px; | ||
font-weight: 700; | ||
} | ||
|
||
.container .profile-data .info p{ | ||
font-size: 15px; | ||
font-weight: 400; | ||
line-height: 23px; | ||
} | ||
|
||
/* REPOSITORIES */ | ||
|
||
.container .profile-data .repositories h2{ | ||
margin-bottom: 30px; | ||
text-align: center; | ||
} | ||
|
||
.container .profile-data .repositories ul{ | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
} | ||
|
||
.container .profile-data .repositories ul li a{ | ||
padding: 20px; | ||
border: 1px solid grey; | ||
margin: 20px; | ||
display: block; | ||
border-radius: 7px; | ||
transition: 0.3s ease-in-out; | ||
} | ||
|
||
.container .profile-data .repositories ul li a:hover{ | ||
background-color:hotpink; | ||
color: #fff | ||
} | ||
|
||
.container .profile-data.hide{ | ||
display: none; | ||
} | ||
|
||
@media (max-width: 1280px) { | ||
.container { | ||
flex-direction: column; | ||
width: 90%; | ||
border-radius: 20px; | ||
} | ||
|
||
.container header { | ||
width: 100%; | ||
} | ||
|
||
.container header h1 { | ||
font-size: 24px; | ||
text-align: center; | ||
} | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.container header #input-search, | ||
.container header #btn-search | ||
{ | ||
width: 100%; | ||
} | ||
} | ||
|
||
@media (max-width: 425px) { | ||
main { | ||
padding: 15% 0; | ||
} | ||
|
||
.container .profile-data .info img{ | ||
margin-bottom: 20px; | ||
} | ||
|
||
.container .profile-data .info img, | ||
.container .profile-data .info .data | ||
{ | ||
width: 100%; | ||
padding: 0; | ||
} | ||
} |
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,65 @@ | ||
// Importando serviços | ||
|
||
import { fetchUser } from "/src/scripts/services/user.js"; | ||
import { getRepositories } from "/src/scripts/services/repositories.js"; | ||
|
||
// Importando objetos | ||
|
||
import { user } from "/src/scripts/objects/user.js"; | ||
import { screen } from "/src/scripts/objects/screen.js"; | ||
|
||
// 1) Criando o evento de buscar os dados do usuário através do clique do botão | ||
|
||
document.getElementById("btn-search").addEventListener("click", () => { | ||
|
||
const userName = document.getElementById("input-search").value; | ||
|
||
if(validateEmptyInput(userName)) return; | ||
|
||
getUserData(userName); | ||
}) | ||
|
||
// 2) Criando o evento de buscar os dados do usuário através do pressionamento da tecla "enter" | ||
|
||
document.getElementById("input-search").addEventListener("keyup", (e) => { | ||
const userName = e.target.value; | ||
const key = e.which || e.keyCode; | ||
const isEnterKeyPressed = key === 13; | ||
|
||
if(isEnterKeyPressed){ | ||
|
||
if(validateEmptyInput(userName)) return; | ||
|
||
getUserData(userName); | ||
} | ||
}) | ||
|
||
// 3) Função de validação | ||
|
||
function validateEmptyInput(userName){ | ||
|
||
if(userName.length === 0){ | ||
alert("Preencha o campo com o nome do usuário do GitHub"); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
// 4) Criação da função que altera o HTML através dos dados obtidos do usuário via API - dados do usuário | ||
|
||
async function getUserData(userName){ | ||
|
||
const userResponse = await fetchUser(userName); | ||
|
||
if(userResponse.message === "Not Found"){ | ||
screen.renderNotFound(); | ||
return; | ||
} | ||
|
||
const repositoriesResponse = await getRepositories(userName); | ||
|
||
user.setInfo(userResponse); | ||
user.setRepositories(repositoriesResponse); | ||
|
||
screen.renderUser(user); | ||
} |
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,37 @@ | ||
const screen = { | ||
|
||
userProfile: document.querySelector(".profile-data"), | ||
|
||
renderUser(user){ | ||
|
||
// Usuário | ||
|
||
this.userProfile.innerHTML = `<div class = "info"> | ||
<img src = "${user.avatarUrl}" alt = "Foto do perfil usuário" /> | ||
<div class = "data"> | ||
<h1>${user.name ?? "Não possui nome cadastrado 😢"}</h1> | ||
<p>${user.bio ?? "Não possui bio cadastrada 😢"}</p> | ||
</div> | ||
</div>` | ||
|
||
// Repositórios | ||
|
||
let repositoriesItens = "" | ||
|
||
user.repositories.forEach(repo => repositoriesItens += `<li><a href="${repo.html_url}" target = "_blank">${repo.name}</a></li>`); | ||
|
||
if(user.repositories.length > 0){ | ||
this.userProfile.innerHTML += `<div class="repositories section"> | ||
<h2>Repositórios</h2> | ||
<ul>${repositoriesItens}</ul> | ||
</div>` | ||
} | ||
}, | ||
|
||
renderNotFound(){ | ||
this.userProfile.innerHTML = "<h3>Usuário não encontrado!</h3>" | ||
} | ||
|
||
} | ||
|
||
export { screen }; |
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,18 @@ | ||
const user = { | ||
avatarUrl: '', | ||
name: '', | ||
bio: '', | ||
userName: '', | ||
repositories: [], | ||
setInfo(gitHubUser){ | ||
this.avatarUrl = gitHubUser.avatar_url; | ||
this.name = gitHubUser.name; | ||
this.bio = gitHubUser.bio; | ||
this.userName = gitHubUser.login; | ||
}, | ||
setRepositories(repositories){ | ||
this.repositories = repositories; | ||
} | ||
} | ||
|
||
export { user }; |
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,10 @@ | ||
// 1) Criação da função assíncrona para buscar os dados de repositórios | ||
|
||
import { baseUrl, repositoriesQuantity } from "/src/scripts/variables.js"; | ||
|
||
async function getRepositories(userName){ | ||
const response = await fetch(`${baseUrl}/${userName}/repos?per_page=${repositoriesQuantity}`); | ||
return await response.json(); | ||
} | ||
|
||
export { getRepositories }; |
Oops, something went wrong.