Skip to content

Commit

Permalink
week-12 done
Browse files Browse the repository at this point in the history
  • Loading branch information
hol23003 committed Apr 15, 2024
1 parent 569b091 commit fb81c12
Show file tree
Hide file tree
Showing 2 changed files with 500 additions and 0 deletions.
77 changes: 77 additions & 0 deletions week-12/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UConn Github Search</title>
<link rel="stylesheet" href="https://primer.github.io/css/site.css">

<style>
.user-card {
display: flex;
align-items: center;
margin-bottom: 10px;
}

.user-card img {
width: 50px;
height: 50px;
border-radius: 50%;
margin-right: 10px;
}

#search-results {
margin-top: 20px;
}

#search-box {
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container-lg">
<h1>UConn Github Search</h1>
<div id="search-box">
<input type="text" id="search-input" placeholder="Enter search term">
<button onclick="searchUsers()">Search</button>
</div>
<div id="search-results"></div>
</div>

<script>
function searchUsers() {
const searchTerm = document.getElementById('search-input').value.trim().toLowerCase();
if (searchTerm.length < 3) {
alert("Please enter at least 3 characters for your search.");
return;
}

const apiUrl = `users.json`;

fetch(apiUrl)
.then(response => response.json())
.then(data => showSearchResults(data.items, searchTerm))
.catch(error => console.error('Error fetching users:', error));
}

function showSearchResults(users, searchTerm) {
const searchResults = document.getElementById('search-results');

if (users.length === 0) {
searchResults.innerHTML = `<p>No results found for "${searchTerm}"</p>`;
} else {
searchResults.innerHTML = `<p>Found ${users.length} results for "${searchTerm}":</p>`;
const userListHTML = users.map(user => `
<div class="user-card">
<img src="${user.avatar_url}" alt="Avatar">
<a href="${user.html_url}" target="_blank">${user.login}</a>
</div>
`).join('');
searchResults.innerHTML += userListHTML;
}
}

</script>
</body>
</html>
Loading

0 comments on commit fb81c12

Please sign in to comment.