Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
modified search
- Loading branch information
Showing
6 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,41 @@ | ||
|
||
const search = 'https://github.uconn.edu/api/v3/search/users?q='; | ||
|
||
|
||
function numResults(n) { | ||
if (n < 1) { | ||
return "Nothing found. Try another search."; | ||
} else if (n === 1) { | ||
return "Found 1 result"; | ||
} else { | ||
return "Found " + n + " results:"; | ||
} | ||
} | ||
let form = document.querySelector("button.btn-primary"). | ||
form.addEventListener('submit', function(event) { | ||
event.preventDefault(); | ||
|
||
if (event.target[0].value.length === 0) { | ||
document.getElementById("number").innerHTML = "No search found. Try again." | ||
} else | ||
|
||
return fetch(search + event.target[0].value) | ||
.then(response => response.json()) | ||
.then(data => { | ||
|
||
var items = data["total_count"]; | ||
|
||
|
||
document.getElementById("number").innerHTML = numResults(items); | ||
|
||
|
||
document.getElementById("results").innerHTML = ""; | ||
|
||
|
||
for (i = 0; i < items; i++) { | ||
document.getElementById("results").innerHTML += '<a href="' + data["items"][i].html_url + '" class="card"><img src="' + data["items"][i].avatar_url + '" alt="' + data["items"][i].login + ' Avatar"><h2>' + data["items"][i].login + '</h2></a>'; | ||
} | ||
|
||
}) | ||
.catch(error => console.error(error)) | ||
}) |