-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.tsx
187 lines (164 loc) · 5.86 KB
/
User.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
import { useEffect, useContext } from 'react';
import { useParams, Link } from 'react-router-dom';
import { FaCodepen, FaStore, FaUserFriends, FaUsers } from 'react-icons/fa';
import Spinner from '../components/layout/Spinner';
import RepoList from '../components/repos/RepoList';
import GithubContext from '../context/github/GithubContext';
import { getUserAndRepos } from '../context/github/GithubActions';
export default function User(): JSX.Element {
const { user, loading, repos, dispatch } = useContext(GithubContext);
const {
name,
type,
avatar_url,
location,
bio,
blog,
twitter_username,
login,
html_url,
followers,
following,
public_repos,
public_gists,
hireable,
} = user;
const params = useParams();
useEffect(() => {
dispatch({ type: 'SET_LOADING' });
const getUserData = async () => {
if (params.login) {
const userData = await getUserAndRepos(params.login);
dispatch({ type: 'GET_USER_AND_REPOS', payload: userData });
}
};
getUserData();
}, [dispatch, params.login]);
if (loading) {
return <Spinner />;
}
// NOTE: check for valid url to users website
const websiteUrl = blog?.startsWith('http') ? blog : 'https://' + blog;
// NOTE: code here has been fixed so that stats no longer show scroll bar on
// mobile / small devices
// https://www.udemy.com/course/react-front-to-back-2022/learn/lecture/29768968#questions/16902278
return (
<>
<div className='w-full mx-auto lg:w-10/12'>
<div className='mb-4'>
<Link to='/' className='btn btn-ghost'>
Back To Search
</Link>
</div>
<div className='grid grid-cols-1 xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-3 mb-8 md:gap-8'>
<div className='custom-card-image mb-6 md:mb-0'>
<div className='rounded-lg shadow-xl card image-full'>
<figure>
<img src={avatar_url} alt='' />
</figure>
<div className='card-body justify-end'>
<h2 className='card-title mb-0'>{name}</h2>
<p>{login}</p>
</div>
</div>
</div>
<div className='col-span-2'>
<div className='mb-6'>
<h1 className='text-3xl card-title'>
{name}
<div className='ml-2 mr-1 badge badge-success'>{type}</div>
{hireable && (
<div className='mx-1 badge badge-info'>Hireable</div>
)}
</h1>
<p>{bio}</p>
<div className='mt-4 card-actions'>
<a
href={html_url}
target='_blank'
rel='noreferrer'
className='btn btn-outline'
>
Visit Github Profile
</a>
</div>
</div>
<div className='w-full rounded-lg shadow-md bg-base-100 stats'>
{location && (
<div className='stat'>
<div className='stat-title text-md'>Location</div>
<div className='text-lg stat-value'>{location}</div>
</div>
)}
{blog && (
<div className='stat'>
<div className='stat-title text-md'>Website</div>
<div className='text-lg stat-value'>
<a href={websiteUrl} target='_blank' rel='noreferrer'>
{websiteUrl}
</a>
</div>
</div>
)}
{twitter_username && (
<div className='stat'>
<div className='stat-title text-md'>Twitter</div>
<div className='text-lg stat-value'>
<a
href={`https://twitter.com/${twitter_username}`}
target='_blank'
rel='noreferrer'
>
{twitter_username}
</a>
</div>
</div>
)}
</div>
</div>
</div>
<div className='w-full py-5 mb-6 rounded-lg shadow-md bg-base-100 stats'>
<div className='grid grid-cols-1 md:grid-cols-3'>
<div className='stat'>
<div className='stat-figure text-secondary'>
<FaUsers className='text-3xl md:text-5xl' />
</div>
<div className='stat-title pr-5'>Followers</div>
<div className='stat-value pr-5 text-3xl md:text-4xl'>
{followers}
</div>
</div>
<div className='stat'>
<div className='stat-figure text-secondary'>
<FaUserFriends className='text-3xl md:text-5xl' />
</div>
<div className='stat-title pr-5'>Following</div>
<div className='stat-value pr-5 text-3xl md:text-4xl'>
{following}
</div>
</div>
<div className='stat'>
<div className='stat-figure text-secondary'>
<FaCodepen className='text-3xl md:text-5xl' />
</div>
<div className='stat-title pr-5'>Public Repos</div>
<div className='stat-value pr-5 text-3xl md:text-4xl'>
{public_repos}
</div>
</div>
<div className='stat'>
<div className='stat-figure text-secondary'>
<FaStore className='text-3xl md:text-5xl' />
</div>
<div className='stat-title pr-5'>Public Gists</div>
<div className='stat-value pr-5 text-3xl md:text-4xl'>
{public_gists}
</div>
</div>
</div>
</div>
<RepoList repos={repos} />
</div>
</>
);
}