Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions src/components/Introbar/Introbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useTransition } from "react";
import { useState, useTransition } from "react";
import "./Introbar.css";
import Profilebox from "../Profilebox/Profilebox";

Expand All @@ -8,9 +8,11 @@ const Introbar = () => {
const [userData, setUserData] = useState({});
const [userFound, setUserFound] = useState<any | null>(null);

const [repos,setRepos] = useState([]);
const [repos, setRepos] = useState([]);
const [followers, setFollowers] = useState([]);
const [following, setFollowing] = useState([]);

const handleChange = (event:any) => {
const handleChange = (event: any) => {
event.preventDefault();
startTransition(() => {
fetch(`https://api.github.com/users/${userName}`)
Expand All @@ -21,13 +23,23 @@ const Introbar = () => {
return res.json();
})
.then((data) => {
fetch(data.repos_url)
.then((res) => res.json())
.then((data) => {
setRepos(data);
});
// Remove {/other_user} from the following_url
const followingUrl = data.following_url.replace("{/other_user}", "");

// Fetch data for repos, followers, and following
Promise.all([
fetch(data.repos_url).then((res) => res.json()),
fetch(data.followers_url).then((res) => res.json()),
fetch(followingUrl).then((res) => res.json()),
]).then(([reposData, followersData, followingData]) => {
setRepos(reposData);
setFollowers(followersData);
setFollowing(followingData);
});

// Set user data and name
setUserData(data);
setUserName(data.login)
setUserName(data.login);
setUserFound(true);
})
.catch((error) => {
Expand All @@ -49,22 +61,29 @@ const Introbar = () => {
Effortless and efficient exploration !
</h4>
<div className="searchbox">
<form onSubmit={handleChange}>
<input
value={userName}
onChange={(e) => {setUserName(e.target.value)}}
type="text"
placeholder="Search for a user"
/>
<button onClick={handleChange}>Search</button>
</form>
<form onSubmit={handleChange}>
<input
value={userName}
onChange={(e) => {
setUserName(e.target.value);
}}
type="text"
placeholder="Search for a user"
/>
<button onClick={handleChange}>Search</button>
</form>
</div>
</section>
{userFound ? (
isPending ? (
<h1 className="showinfo">Searching...</h1>
) : (
<Profilebox profileData={userData} repos={repos} />
<Profilebox
profileData={userData}
repos={repos}
followers={followers}
following={following}
/>
)
) : userFound != null ? (
<h1 className="showinfo">No User Found</h1>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Profilebox/Profilebox.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
background-image: linear-gradient(rgb(0, 0, 0), rgb(43, 43, 42));
opacity: 0.8;
border-radius: 20px;
box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px,
rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px,
rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
padding: 30px;
}
.databox .profilebox {
Expand Down Expand Up @@ -103,7 +105,9 @@
}
.databox .profiledetails .repobox a .repo {
border-radius: 20px;
box-shadow: rgba(240, 46, 170, 0.4) -5px 5px, rgba(240, 46, 170, 0.3) -10px 10px, rgba(240, 46, 170, 0.2) -15px 15px, rgba(240, 46, 170, 0.1) -20px 20px, rgba(240, 46, 170, 0.05) -25px 25px;
box-shadow: rgba(240, 46, 170, 0.4) -5px 5px,
rgba(240, 46, 170, 0.3) -10px 10px, rgba(240, 46, 170, 0.2) -15px 15px,
rgba(240, 46, 170, 0.1) -20px 20px, rgba(240, 46, 170, 0.05) -25px 25px;
background-color: #000000;
padding: 10px 20px;
}
Expand Down Expand Up @@ -338,4 +342,4 @@
.databox .profiledetails .repobox a .repo .countdetails button {
padding: 5px 5px;
}
}/*# sourceMappingURL=Profilebox.css.map */
} /*# sourceMappingURL=Profilebox.css.map */
Loading