Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
yas
  • Loading branch information
kmr18006 committed Apr 11, 2024
1 parent ff40af0 commit a8f3c21
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion final project/css/style.css
Expand Up @@ -7,7 +7,7 @@ img
background-color: white;
border-style: solid;
border-color: rgb(210, 210, 210);
box-shadow: 0px 0px 10px #d9d9d9;
box-shadow: 0px 0px 10px #0000002d;
}

select {
Expand Down
4 changes: 2 additions & 2 deletions final project/js/script.js
Expand Up @@ -40,8 +40,8 @@ function whileDragging(e) {
return false;

if (mode == 0) {
var newX = e.pageX - 100;
var newY = e.pageY - 400;
var newX = e.pageX - 600;
var newY = e.pageY - 200;
currentlyDragging.css({ 'margin-top': newY + 'px', 'margin-left': newX + 'px' });
} else if (mode == 1) {
if (e.pageY > oldY) {
Expand Down
Binary file added week-12/img/github.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions week-12/index.html
@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub User Search</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.container {
max-width: 600px;
}

img {
width: 150px;
}

#error {
display: none;
}
.list-group-item img {
max-width: 100px;
max-height: 100px;
border-radius: 10px;
}
.list-group-item {
padding-top: 20px;
padding-bottom: 20px;
}
a {
text-decoration: none;
}
</style>

</head>
<body>
<div class="container mt-3">
<div class="d-flex justify-content-center">
<img src="img/github.png" alt="github logo" class="p-3">
</div>
<h2 class="text-center mb-4">User Search</h2>
<div class="row d-flex justify-content-center">
<div class="mb-3 col-10">
<input type="text" id="searchInput" class="form-control" placeholder="Search For User">
</div>
<div class="col-2">
<button id="searchBtn" class="btn btn-primary">Search</button>
</div>
</div>
<div id="error" class="text-danger"></div>

<div id="results" class="mt-4"></div>
</div>

<script>
document.getElementById('searchBtn').addEventListener('click', () => {
const searchInput = document.getElementById('searchInput').value.trim();

if (searchInput.length < 1) {
document.getElementById('error').innerText = 'Please enter at least 1 character.';
document.getElementById('error').style.display = 'block';
return;
}

fetch(`https://github.uconn.edu/api/v3/search/users?q=${searchInput}`)
.then(response => response.json())
.then(data => {
displayResults(data);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
});

function displayResults(data) {
const resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = '';

if (data.items.length === 0) {
document.getElementById('error').innerText = 'No results found.';
document.getElementById('error').style.display = 'block';
return;
}

const totalCount = data.total_count;
const users = data.items;

document.getElementById('error').style.display = 'none';

resultsContainer.innerHTML = `
<div class="alert alert-success" role="alert">${totalCount} results found.</div>
<ul class="list-group">
${users.map(user => `
<li class="list-group-item">
<a href="${user.html_url}" target="_blank">
<img src="${user.avatar_url}" alt="${user.login}" class="me-2">${user.login}
</li>
`).join('')}
</ul>
`;
}

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

0 comments on commit a8f3c21

Please sign in to comment.