|
1 | | -import React, { useState } from 'react'; |
2 | | -import { Header, Input, Icon, Card } from "semantic-ui-react" |
3 | | -import Styles from './styles/style.module.scss'; |
4 | | -import GetUserDetails from "./Utils/GetUserDetails"; |
5 | | -import { ToastContainer, toast } from "react-toastify" |
6 | | - |
7 | | -function App() { |
8 | | - const [Searching, setSearching] = useState(false); |
9 | | - const [Username, setUsername] = useState("") |
10 | | - const [User, setUser] = useState({ avatar_url: "", login: "", name: "", bio: "", followers: 0 }) |
11 | | - |
12 | | - const handleClick = async (e: any) => { |
13 | | - if (Searching) return |
14 | | - setSearching(true) |
15 | | - if (!Username || Username.trim() === "") return setSearching(false) |
16 | | - let NeedToAddStyle = false; |
17 | | - //@ts-ignore ;-; |
18 | | - let deepesh = await GetUserDetails(Username) |
19 | | - if (User.login === "") NeedToAddStyle = true |
20 | | - |
21 | | - //@ts-ignore ; |
22 | | - if (deepesh.error) { |
23 | | - //@ts-ignore ahh shit here we go again lol |
24 | | - toast(deepesh.stack, { |
25 | | - type: "error" |
26 | | - }) |
27 | | - return setSearching(false) |
28 | | - } |
29 | | - |
30 | | - //@ts-ignore ;-; |
31 | | - setUser(deepesh); |
32 | | - if (NeedToAddStyle) document.querySelector("." + Styles.Content)?.setAttribute("style", "display: flex;") |
33 | | - setSearching(false) |
34 | | - } |
35 | | - |
36 | | - const Extra = <div> |
37 | | - <a href={"https://github.com/" + Username }> <Icon name='user' />{User.followers} Followers</a> |
38 | | - </div> |
39 | | - return ( |
40 | | - <div> |
41 | | - <ToastContainer /> |
42 | | - <div className={Styles.MainHeader}> |
43 | | - <Header center aligned={true} inverted size="large">GitHub Stats |
44 | | - <Header.Subheader center aligned={true} inverted>Get anyone's GitHub stats easier in just an single click!</Header.Subheader> |
45 | | - </Header> |
46 | | - </div> |
47 | | - |
48 | | - <div className={Styles.Search}> |
49 | | - <Input disabled={Searching ? true : false} loading={Searching ? true : false} icon={true} placeholder='GreenTreeTeam'> |
50 | | - <input onChange={(e) => setUsername(e.target.value)} /> |
51 | | - <Icon loading={Searching ? true : false} disabled={Searching ? true : false} name='search' inverted circular={true} link={true} onClick={handleClick} /> |
52 | | - </Input> |
53 | | - </div> |
54 | | - |
55 | | - <div className={Styles.Content}> |
56 | | - <Card |
57 | | - image={User.avatar_url} |
58 | | - header={User.name} |
59 | | - meta={User.login} |
60 | | - description={User.bio} |
61 | | - extra={Extra} |
62 | | - /> |
63 | | - </div> |
64 | | - </div> |
65 | | - ); |
66 | | -} |
67 | | - |
68 | | -export default App; |
| 1 | +import React, { useState } from "react"; |
| 2 | +import { Header, Input, Icon, Card } from "semantic-ui-react"; |
| 3 | +import Styles from "./styles/style.module.scss"; |
| 4 | +import GetUserDetails from "./Utils/GetUserDetails"; |
| 5 | +import { ToastContainer, toast } from "react-toastify"; |
| 6 | + |
| 7 | +function App() { |
| 8 | + const [Searching, setSearching] = useState(false); |
| 9 | + const [Username, setUsername] = useState(""); |
| 10 | + const [User, setUser] = useState({ |
| 11 | + avatar_url: "", |
| 12 | + login: "", |
| 13 | + name: "", |
| 14 | + bio: "", |
| 15 | + followers: null, |
| 16 | + following: null, |
| 17 | + location: "", |
| 18 | + type: "", |
| 19 | + created_at: "", |
| 20 | + public_repos: 0, |
| 21 | + public_gists: 0, |
| 22 | + id: 0, |
| 23 | + }); |
| 24 | + |
| 25 | + const handleClick = async (e: any) => { |
| 26 | + if (Searching) return; |
| 27 | + setSearching(true); |
| 28 | + if (!Username || Username.trim() === "") return setSearching(false); |
| 29 | + let NeedToAddStyle = false; |
| 30 | + let userData = await GetUserDetails(Username); |
| 31 | + if (User.login === "") NeedToAddStyle = true; |
| 32 | + |
| 33 | + //@ts-ignore ; |
| 34 | + if (userData.error) { |
| 35 | + //@ts-ignore ahh shit here we go again lol |
| 36 | + toast(userData.stack, { |
| 37 | + type: "error", |
| 38 | + }); |
| 39 | + return setSearching(false); |
| 40 | + //@ts-ignore |
| 41 | + } else if (userData.message) { |
| 42 | + //@ts-ignore |
| 43 | + toast("Github API Rate Limit.", { |
| 44 | + // cuz yes :( |
| 45 | + type: "error", |
| 46 | + }); |
| 47 | + return setSearching(false); |
| 48 | + } |
| 49 | + |
| 50 | + //@ts-ignore ;-; |
| 51 | + setUser(userData); |
| 52 | + if (NeedToAddStyle) |
| 53 | + document.querySelector("." + Styles.Content)?.setAttribute("style", "display: flex;"); |
| 54 | + setSearching(false); |
| 55 | + }; |
| 56 | + |
| 57 | + const handleKeyPress = async (e: any) => { |
| 58 | + e.preventDefault(); |
| 59 | + handleClick(e); |
| 60 | + }; |
| 61 | + |
| 62 | + const Extra = ( |
| 63 | + <div> |
| 64 | + <a target="blank" href={"https://github.com/" + Username}> |
| 65 | + {" "} |
| 66 | + <Icon name="info circle" /> |
| 67 | + {User.followers ? "ID: " + User.id : "ID: Unknown"} |
| 68 | + </a> |
| 69 | + <br /> |
| 70 | + <br /> |
| 71 | + <a target="blank" href={"https://github.com/" + Username}> |
| 72 | + {" "} |
| 73 | + <Icon name="user circle outline" /> |
| 74 | + {User.followers ? "Followers: " + User.followers : "Followers: None"} |
| 75 | + </a> |
| 76 | + <br /> |
| 77 | + <br /> |
| 78 | + <a target="blank" href={"https://github.com/" + Username}> |
| 79 | + {" "} |
| 80 | + <Icon name="user circle outline" /> |
| 81 | + {User.following ? "Following: " + User.following : "Following: None"} |
| 82 | + </a> |
| 83 | + <br /> |
| 84 | + <br /> |
| 85 | + <a target="blank" href={"https://github.com/" + Username}> |
| 86 | + {" "} |
| 87 | + <Icon name="location arrow" /> |
| 88 | + {User.location ? `Location: ` + User.location : "Location: None"} |
| 89 | + </a> |
| 90 | + <br /> |
| 91 | + <br /> |
| 92 | + <a target="blank" href={"https://github.com/" + Username}> |
| 93 | + {" "} |
| 94 | + <Icon name="question circle outline" /> |
| 95 | + {User.type ? `Type: ` + User.type : "Type: Unknown"} |
| 96 | + </a> |
| 97 | + <br /> |
| 98 | + <br /> |
| 99 | + <a target="blank" href={"https://github.com/" + Username}> |
| 100 | + {" "} |
| 101 | + <Icon name="calendar times outline" /> |
| 102 | + {User.created_at |
| 103 | + ? `Created At: ` + |
| 104 | + new Date(User.created_at).toLocaleDateString() + |
| 105 | + " " + |
| 106 | + new Date(User.created_at).toLocaleTimeString() |
| 107 | + : "Created At: Unknown Date"} |
| 108 | + </a> |
| 109 | + <br /> |
| 110 | + <br /> |
| 111 | + <a target="blank" href={"https://github.com/" + Username + "?tab=repositories"}> |
| 112 | + {" "} |
| 113 | + <Icon name="github" /> |
| 114 | + {User.public_repos === 0 |
| 115 | + ? "Public Repos: No Repos" |
| 116 | + : "Public Repos: " + User.public_repos + " Repos"} |
| 117 | + </a> |
| 118 | + <br /> |
| 119 | + <br /> |
| 120 | + <a target="blank" href={"https://gist.github.com/" + Username}> |
| 121 | + {" "} |
| 122 | + <Icon name="github" /> |
| 123 | + {User.public_gists === 0 |
| 124 | + ? "Public Gists: No Gists" |
| 125 | + : "Public Gists: " + User.public_gists + " Gists"} |
| 126 | + </a> |
| 127 | + </div> |
| 128 | + ); |
| 129 | + return ( |
| 130 | + <div> |
| 131 | + <ToastContainer /> |
| 132 | + <div className={Styles.MainHeader}> |
| 133 | + <Header center aligned={true} inverted size="large"> |
| 134 | + GitHub Stats |
| 135 | + <Header.Subheader center aligned={true} inverted> |
| 136 | + Get anyone's GitHub stats easier in just an single click! |
| 137 | + </Header.Subheader> |
| 138 | + </Header> |
| 139 | + </div> |
| 140 | + |
| 141 | + <div className={Styles.Search}> |
| 142 | + <form onSubmit={handleKeyPress}> |
| 143 | + <Input |
| 144 | + disabled={Searching ? true : false} |
| 145 | + loading={Searching ? true : false} |
| 146 | + icon={true} |
| 147 | + placeholder="GreenTreeTeam" |
| 148 | + > |
| 149 | + <input |
| 150 | + onChange={(e) => |
| 151 | + setUsername(e.target.value.trim().split(/ +/g).join("-")) |
| 152 | + } |
| 153 | + /> |
| 154 | + <Icon |
| 155 | + loading={Searching ? true : false} |
| 156 | + disabled={Searching ? true : false} |
| 157 | + name="search" |
| 158 | + inverted |
| 159 | + circular={true} |
| 160 | + link={true} |
| 161 | + onClick={handleClick} |
| 162 | + /> |
| 163 | + </Input> |
| 164 | + </form> |
| 165 | + </div> |
| 166 | + |
| 167 | + <div className={Styles.Content}> |
| 168 | + <Card |
| 169 | + image={User.avatar_url} |
| 170 | + header={User.name} |
| 171 | + meta={User.login} |
| 172 | + description={User.bio ? User.bio : "No Bio"} |
| 173 | + extra={Extra} |
| 174 | + raised={true} |
| 175 | + /> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + ); |
| 179 | +} |
| 180 | + |
| 181 | +export default App; |
0 commit comments