Skip to content

Commit

Permalink
firstcommit
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianoMariano committed Jan 22, 2024
0 parents commit d9b617f
Show file tree
Hide file tree
Showing 4,226 changed files with 580,354 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 14 additions & 0 deletions JS/GithubUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class GithubUser {
static search(username) {
const endpoint = `https://api.github.com/users/${username}`

return fetch(endpoint)
.then(data => data.json())
.then(({ login, name, public_repos, followers }) => ({
login,
name,
public_repos,
followers
}))
}
}
128 changes: 128 additions & 0 deletions JS/favorites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { GithubUser } from "./GithubUser.js"

export class Favorites {
constructor(root) {
this.root = document.querySelector(root)
this.load()
}

load() {
this.entries = JSON.parse(localStorage.getItem('@github-favorites:')) || []
}

save() {
localStorage.setItem('@github-favorites:', JSON.stringify(this.entries))
}

async add(username) {
try {
const userExists = this.entries.find(entry => entry.login === username)

if(userExists){
throw new Error('Usuario já cadastrado!!')
}

const user = await GithubUser.search(username)

if(user.login === undefined) {
throw new Error('Usuário não encontrado!!!')
}

this.entries = [user, ...this.entries]
this.update()
this.save()

} catch (error){
alert(error.message)
}
}

delete(user) {
const filteredEntries = this.entries.filter(entry => entry.login !== user.login)
this.entries = filteredEntries
this.update()
this.save()
}
}

export class FavoritesView extends Favorites {
constructor(root) {
super(root)

this.tbody = this.root.querySelector('table tbody')

this.update()
this.onadd()
}

onadd() {
const addButton = this.root.querySelector('.search button')
addButton.onclick = () => {
const { value } = this.root.querySelector('.search input')
this.add(value)
}
}

update() {
this.removeAllTr()

this.entries.forEach(user => {
const row = this.createRow()

row.querySelector('.user img').src = `https://github.com/${user.login}.png`

row.querySelector('.user img').alt = `Imagem de ${user.name}`

row.querySelector('.user a').href = `https://github.com/${user.login}`

row.querySelector('.user p').textContent = user.name

row.querySelector('.user span').textContent = user.login

row.querySelector('.repositories').textContent = user.public_repos

row.querySelector('.followers').textContent = user.followers

row.querySelector('.remove')
.onclick = () => {
const isOk = confirm('Tem certeza que deseja remover essa linha?')
if(isOk) {
this.delete(user)
}
}

this.tbody.append(row)
})
}

createRow() {
const tr = document.createElement('tr')

tr.innerHTML = `
<td class="user">
<img
src="https://github.com/JulianoMariano.png"
alt="Img de juliano">
<a
href="https://github.com/JulianoMariano"
target="_blank">
<p>Juliano Mariano</p>
<span>JulianoMariano</span>
</a>
</td>
<td class="repositories">10</td>
<td class="followers">2</td>
<td>
<button class="remove">&times;</button></td>
`
return tr
}

removeAllTr() {
this.tbody.querySelectorAll('tr')
.forEach((tr) => {
tr.remove()
})
}
}
3 changes: 3 additions & 0 deletions JS/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FavoritesView } from "./favorites.js";

new FavoritesView('#app')
Binary file added assets/gitlogo.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions assets/starbutton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{🌟}GitFav</title>

<link rel="shortcut icon" href="./assets/gitlogo.ico" type="image/x-icon">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">

<script type="module" src="./JS/main.js" defer></script>
</head>
<body>
<div id="app">
<header>
<h1><img src="./assets/svg.svg" alt=""></h1>
<div class="search">
<label class="sr-only" for="input-search">Usuario do Github</label>
<input type="text" placeholder="Username do usuario que deseja favoritar">
<button><img src="./assets/starbutton.svg" alt=""> favoritar </button>
</div>
</header>
<table>
<thead>
<tr>
<th>Usuário</th>
<th>Repositórios</th>
<th>Seguidores</th>
<th>Ação</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>
16 changes: 16 additions & 0 deletions node_modules/.bin/browser-sync

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

17 changes: 17 additions & 0 deletions node_modules/.bin/browser-sync.cmd

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

28 changes: 28 additions & 0 deletions node_modules/.bin/browser-sync.ps1

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

16 changes: 16 additions & 0 deletions node_modules/.bin/dev-ip

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

17 changes: 17 additions & 0 deletions node_modules/.bin/dev-ip.cmd

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

28 changes: 28 additions & 0 deletions node_modules/.bin/dev-ip.ps1

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

16 changes: 16 additions & 0 deletions node_modules/.bin/lite-server

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

17 changes: 17 additions & 0 deletions node_modules/.bin/lite-server.cmd

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

Loading

0 comments on commit d9b617f

Please sign in to comment.