forked from bpd01001/dmd-3475-assignment-repo
-
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
Showing
2 changed files
with
500 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,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> |
Oops, something went wrong.