Skip to content

Commit 42f9f10

Browse files
committed
update the code
1 parent a375e57 commit 42f9f10

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

Source-Code/GithubProfileFinder/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
placeholder="Enter Github UserName"
2525
class=""
2626
/>
27-
<div id="search" onclick="getUser()">Search User</div>
27+
<button id="search">Search User</button>
2828
</div>
2929

3030
<div class="profile-card">
+15-17
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
1-
// API USED => https://api.github.com/user/user_name
2-
3-
let input_user = document.querySelector("#input");
1+
const inputUser = document.querySelector("#input");
42

53
const userImg = document.querySelector(".main-info");
6-
// const name = document.querySelector("#name");
7-
// const userName =document.querySelector("#username");
4+
const search = document.getElementById("search");
85
const bio = document.querySelector("#bio");
96
const repos = document.querySelector("#repo");
107
const followers = document.querySelector("#followers");
118
const following = document.querySelector("#following");
129

13-
const fetchUser = (user_name) => {
14-
fetch(`https://api.github.com/users/${user_name}`)
10+
const fetchUser = (username) => {
11+
fetch(`https://api.github.com/users/${username}`)
1512
.then((data) => data.json())
1613
.then((jsonData) => {
17-
if (jsonData.message == "Not found") {
14+
if (jsonData.message === "Not Found") {
1815
alert("User Not Found");
1916
return;
20-
// console.log("Error" + jsonData.message);
2117
} else {
2218
userImg.innerHTML = `
2319
<img src="${jsonData.avatar_url}" alt="avatar" id="prof-img">
2420
<span class="name" id="name">${jsonData.name}</span>
2521
<a href="${jsonData.html_url}" id="username">@${jsonData.login}</a>
2622
`;
27-
bio.innerHTML = jsonData.bio;
23+
bio.innerHTML = jsonData.bio ? jsonData.bio : "No bio available.";
2824
repos.innerHTML = jsonData.public_repos;
2925
followers.innerHTML = jsonData.followers;
3026
following.innerHTML = jsonData.following;
3127
}
3228
})
3329
.catch((err) => {
34-
console.log("Catch" + err.message);
30+
console.log("Catch: " + err.message);
3531
});
3632
};
3733

3834
const getUser = () => {
39-
let user_name = input_user.value.trim();
40-
// trim will replace before and after spaces
35+
let username = inputUser.value.trim();
4136

42-
if (user_name.length == 0) {
43-
alert("Please enter a valid github username");
37+
if (username.length === 0) {
38+
alert("Please enter a valid GitHub username");
4439
} else {
45-
fetchUser(user_name);
40+
fetchUser(username);
4641
}
4742

48-
input_user.value = " ";
43+
inputUser.value = "";
4944
};
45+
46+
// Attach event listener to the search button
47+
search.addEventListener("click", getUser);

Source-Code/GithubProfileFinder/style.css

+10-22
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,22 @@ body{
1111
background-position: center;
1212
background-blend-mode: darken;
1313
}
14-
.container{
15-
width: 100%;
16-
}
14+
1715

1816
.search-container{
19-
position: relative;
17+
2018
width: 550px;
2119
height: 50px;
2220
background-color: #fff;
23-
border-radius: 15px;
24-
overflow: hidden;
2521
display: flex;
26-
justify-content: center;
27-
align-items: center;
28-
flex-direction: column;
22+
justify-content: space-evenly;
2923
margin: 0 auto;
30-
margin-top: 50px;
24+
margin-top: 50px;
3125
box-shadow: 0 3px 10px gray;
3226
}
3327

3428
#input{
35-
width: 100%;
29+
width: 70%;
3630
height: 100%;
3731
background-color: #fff;
3832
border: none;
@@ -42,14 +36,9 @@ body{
4236
}
4337

4438
#search{
45-
width: 160px;
39+
4640
height: 100%;
47-
position: absolute;
48-
top: 0;
49-
right: 0;
50-
display: flex;
51-
justify-content: center;
52-
align-items: center;
41+
width: 30%;
5342
background-color: #000;
5443
color : white;
5544
cursor: pointer;
@@ -60,8 +49,7 @@ body{
6049
padding: auto;
6150
width: 500px;
6251
background-color: rgba(255,255,255,0.6);
63-
margin: 0 auto;
64-
margin-top: 30px;
52+
margin: 25px auto;
6553
border-radius: 15px;
6654
overflow: hidden;
6755
margin-bottom: 15px;
@@ -104,7 +92,7 @@ a{
10492
.bio{
10593
width: 100%;
10694
text-align: center;
107-
padding: 20px 0;
95+
padding: 20px 10px;
10896
font-size: 23px;
10997
}
11098

@@ -144,7 +132,7 @@ p{
144132
overflow: hidden;
145133
margin-bottom: 15px;
146134
box-shadow: 0 3px 10px gray;
147-
font-family: 'Lobster Two', cursive;
135+
font-family: 'Lobster Two';
148136
}
149137
}
150138

0 commit comments

Comments
 (0)