-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (37 loc) · 1.71 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
async function handleSearch() {
const username = document.getElementById('username').value;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
try {
const response = await fetch(`https://collab-backend-jbkc.onrender.com/find-collaborators/${username}`);
if (!response.ok) throw new Error('Network response was not ok');
const collaborators = await response.json();
collaborators.forEach(collaborator => {
const collaboratorElement = document.createElement('div');
collaboratorElement.classList.add('result-item');
const avatar = document.createElement('img');
avatar.src = collaborator.avatar_url;
avatar.alt = collaborator.login;
const infoDiv = document.createElement('div');
infoDiv.classList.add('result-info');
const name = document.createElement('h3');
name.textContent = collaborator.login;
const link = document.createElement('p');
const anchor = document.createElement('a');
anchor.href = collaborator.html_url;
anchor.textContent = collaborator.html_url;
anchor.target = '_blank';
link.appendChild(anchor);
infoDiv.appendChild(name);
infoDiv.appendChild(link);
collaboratorElement.appendChild(avatar);
collaboratorElement.appendChild(infoDiv);
resultsDiv.appendChild(collaboratorElement);
});
} catch (error) {
console.error('Error fetching collaborators:', error);
const errorMessage = document.createElement('p');
errorMessage.textContent = 'Failed to fetch collaborators. Please try again later.';
resultsDiv.appendChild(errorMessage);
}
}