|
| 1 | +/* eslint-disable jsx-a11y/anchor-is-valid */ |
| 2 | +import React, { useEffect, useState } from "react"; |
| 3 | +import { FaXTwitter } from "react-icons/fa6"; |
| 4 | +import { BsGlobe2 } from "react-icons/bs"; |
| 5 | +import { AiOutlineGithub } from "react-icons/ai"; |
| 6 | +import axios from "axios"; |
| 7 | + |
| 8 | +const Homepage = () => { |
| 9 | + const [inputSearch, setInputSearch] = useState(""); |
| 10 | + const [user, setUser] = useState(""); |
| 11 | + const [gitHubUser, setGithubUser] = useState([]); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + if (user) { |
| 15 | + axios |
| 16 | + .get(`https://api.github.com/users/${user}`) |
| 17 | + .then((res) => { |
| 18 | + setGithubUser(res.data); |
| 19 | + }) |
| 20 | + .catch(() => { |
| 21 | + console.log("Some error occured"); |
| 22 | + }); |
| 23 | + } |
| 24 | + }, [user]); |
| 25 | + |
| 26 | + var JoinedDate = new Date(gitHubUser.created_at) |
| 27 | + .toLocaleDateString("en-GB", { |
| 28 | + day: "numeric", |
| 29 | + month: "short", |
| 30 | + year: "numeric", |
| 31 | + }) |
| 32 | + .split(" ") |
| 33 | + .join(" "); |
| 34 | + |
| 35 | + return ( |
| 36 | + <> |
| 37 | + <div className=""> |
| 38 | + <div className="pt-2"> |
| 39 | + <div className="flex justify-center py-5"> |
| 40 | + <h2 className="text-3xl font-bold">DevFinder</h2> |
| 41 | + </div> |
| 42 | + <div className="flex justify-center items-center gap-3"> |
| 43 | + <input |
| 44 | + type="text" |
| 45 | + value={inputSearch} |
| 46 | + onChange={(e) => { |
| 47 | + setInputSearch(e.target.value); |
| 48 | + }} |
| 49 | + placeholder="Enter your Github Username" |
| 50 | + className="p-3 w-1/2 rounded-lg border hover:border hover:border-indigo-950 transition" |
| 51 | + /> |
| 52 | + <button |
| 53 | + type="button" |
| 54 | + onClick={() => { |
| 55 | + setUser(inputSearch); |
| 56 | + }} |
| 57 | + className="flex py-3 px-6 tracking-wide rounded-lg bg-indigo-950 text-white font-semibold" |
| 58 | + > |
| 59 | + Search |
| 60 | + </button> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + {user &&( |
| 64 | + <div className="flex justify-center mt-6"> |
| 65 | + <div className="bg-white-500 shadow-md flex rounded-lg w-3/5"> |
| 66 | + <div className="flex justify-center items-center p-5 border border-l-0 border-t-0 border-b-0 border-r-stone-400 "> |
| 67 | + <img |
| 68 | + src={gitHubUser.avatar_url} |
| 69 | + alt="" |
| 70 | + className="w-56 rounded-full cursor-pointer" |
| 71 | + /> |
| 72 | + </div> |
| 73 | + <div className="p-5 w-full"> |
| 74 | + <div className="flex items-center justify-between"> |
| 75 | + <h2 className="font-semibold text-xl">{gitHubUser.name}</h2> |
| 76 | + <p className="text-gray-400"> |
| 77 | + Joined {JoinedDate} |
| 78 | + </p> |
| 79 | + </div> |
| 80 | + <div className="flex justify-between items-center py-4"> |
| 81 | + <h2 className="font-semibold"> |
| 82 | + Repo : {gitHubUser.public_repos} |
| 83 | + </h2> |
| 84 | + <h2 className="font-semibold"> |
| 85 | + Follower : {gitHubUser.followers} |
| 86 | + </h2> |
| 87 | + <h2 className="font-semibold"> |
| 88 | + Following : {gitHubUser.following} |
| 89 | + </h2> |
| 90 | + </div> |
| 91 | + <div> |
| 92 | + <p>{gitHubUser.bio}</p> |
| 93 | + </div> |
| 94 | + <div className="flex py-4 gap-5 items-center"> |
| 95 | + <a |
| 96 | + href={`https://twitter.com/${gitHubUser.twitter_username}`} |
| 97 | + > |
| 98 | + <FaXTwitter size="1.3rem" className="cursor-pointer" /> |
| 99 | + </a> |
| 100 | + <a href={gitHubUser.blog}> |
| 101 | + <BsGlobe2 size="1.2rem" className="cursor-pointer" /> |
| 102 | + </a> |
| 103 | + <a href={gitHubUser.html_url}> |
| 104 | + <AiOutlineGithub |
| 105 | + size="1.3rem" |
| 106 | + className="scale-110 cursor-pointer" |
| 107 | + /> |
| 108 | + </a> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + )} |
| 114 | + </div> |
| 115 | + </> |
| 116 | + ); |
| 117 | +}; |
| 118 | + |
| 119 | +export default Homepage; |
0 commit comments