/
profile.tsx
212 lines (184 loc) · 9.29 KB
/
profile.tsx
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { useEffect, useState } from "react";
import { FaBrain, FaChevronLeft, FaRobot } from "react-icons/fa";
import { RiLinkedinFill, RiLinkM, RiTwitterFill } from "react-icons/ri";
import { SiC, SiCplusplus, SiCsharp, SiGoland, SiJavascript, SiPhp, SiPython, SiReact, SiRuby, SiRust, SiTypescript } from "react-icons/si";
import { DiJava } from "react-icons/di";
import OpenSaucedLogo from "../../assets/opensauced-logo.svg";
import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/fetchOpenSaucedApiData";
import { emojify } from "node-emoji";
import { goBack, goTo } from "react-chrome-extension-router";
import { getRelativeDays } from "../../utils/dateUtils";
import { getUserPRVelocity } from "../../utils/getUserPRVelocity";
import { BiExit } from "react-icons/bi";
import Start from "./start";
import { optLogOut } from "../../utils/checkAuthentication";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../constants";
const interestIcon = {
python: <SiPython />,
java: <DiJava />,
javascript: <SiJavascript />,
typescript: <SiTypescript />,
csharp: <SiCsharp />,
cpp: <SiCplusplus />,
c: <SiC />,
php: <SiPhp />,
ruby: <SiRuby />,
react: <SiReact />,
ml: <FaBrain />,
ai: <FaRobot />,
golang: <SiGoland />,
rust: <SiRust />,
};
type InterestIconKeys = keyof typeof interestIcon;
export const Profile = ({ username }: { username: string }) => {
const [user, setUser] = useState<null | { id: string, user_name: string, bio: string, created_at: string, linkedin_url: string, twitter_username: string, blog: string, interests: string, open_issues: number }>(null);
const [userPR, setUserPR] = useState<null | { meta: { itemCount: number } }>(null);
const [userHighlights, setUserHighlights] = useState<null | { meta: { itemCount: number } }>(null);
const [userPRVelocity, setUserPRVelocity] = useState<number>(0);
useEffect(() => {
const fetchUserData = async () => {
const [userData, userPRData, userHighlightsData] = await Promise.all([getUserData(username), getUserPRData(username), getUserHighlightsData(username)]);
setUser(userData);
setUserPR(userPRData);
setUserHighlights(userHighlightsData);
setUserPRVelocity(getUserPRVelocity(userPRData?.data || []));
};
void fetchUserData();
}, []);
return (
<div className="p-4 bg-slate-800">
<div className="grid grid-cols-1 divide-y divider-y-center-2 min-w-[320px] text-white">
<header className="flex justify-between">
<div className="flex items-center gap-2">
<button
className="rounded-full p-2 bg-slate-700 hover:bg-slate-700/50"
onClick={() => {
goBack();
}}
>
<FaChevronLeft className="text-osOrange" />
</button>
<img
alt="OpenSauced logo"
className="w-[100%]"
src={OpenSaucedLogo}
/>
</div>
<button
className="flex items-center bg-slate-700 hover:bg-slate-700/70 hover:text-red-600 text-white gap-1 p-1.5 px-2 w-fit rounded-md font-medium text-sm"
onClick={() => {
optLogOut();
goTo(Start);
}}
>
<BiExit />
Log Out
</button>
</header>
<main>
<div className="flex flex-col items-center gap-1 mb-4">
<a
className="flex flex-col items-center hover:text-orange hover:scale-105"
href={`https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}`}
rel="noopener noreferrer"
target="_blank"
>
<img
alt="User avatar"
className="rounded-full w-14 aspect-square p-1 bg-slate-700"
src={`https://github.com/${username}.png`}
/>
<p className="font-medium">
@
{username}
</p>
</a>
{(user?.linkedin_url || user?.twitter_username) &&
<div className="social flex gap-0.5">
{user.linkedin_url &&
<a
className="rounded-sm border bg-slate-700 hover:bg-slate-700/50 hover:text-cyan-400 p-1"
href={user.linkedin_url}
rel="noreferrer"
target="_blank"
title={user.linkedin_url}
>
<RiLinkedinFill className="text-lg" />
</a>}
{user.twitter_username &&
<a
className="rounded-sm border bg-slate-700 hover:bg-slate-700/50 hover:text-cyan-400 p-1"
href={`https://twitter.com/${user.twitter_username}`}
rel="noreferrer"
target="_blank"
title={`https://twitter.com/${user.twitter_username}`}
>
<RiTwitterFill className="text-lg" />
</a>}
</div>}
{user?.bio && (
<span>
{emojify(user.bio)}
</span>
)}
{user?.blog &&
<a
className="flex text-orange items-center gap-0.5"
href={user.blog}
rel="noreferrer"
target="_blank"
>
<RiLinkM />
{user.blog}
</a>}
</div>
<div className="grid grid-cols-2 text-white bg-osOrange -mx-4 mb-4 p-4 py-8">
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>Total Highlights</p>
<p className="font-medium text-5xl">
{userHighlights?.meta.itemCount}
</p>
</div>
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>PR Count</p>
<p className="font-medium text-5xl">
{userPR?.meta.itemCount}
</p>
</div>
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>Avg PRs Velocity</p>
<p className="font-medium text-5xl">
{getRelativeDays(userPRVelocity)}
</p>
</div>
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>Contributed Repos</p>
<p className="font-medium text-5xl">-</p>
</div>
</div>
<div>
<h2 className="font-medium text-lg mb-2">Current Interest</h2>
<div
className="flex gap-1.5"
style={{ flexWrap: "wrap" }}
>
{user?.interests.split(",").map(interest => (
<a
key={interest}
className="flex gap-1 items-center p-1.5 px-4 rounded-full bg-slate-700 hover:bg-slate-700/50"
href={`https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/${interest}/dashboard/filter/recent`}
rel="noreferrer"
target="_blank"
title={`https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/${interest}/dashboard/filter/recent`}
>
{interestIcon[interest as InterestIconKeys]}
{interest}
</a>
))}
</div>
</div>
</main>
</div>
</div>
);
};