Skip to content

Commit 789bc14

Browse files
committed
add Profile component
1 parent a2ea0fa commit 789bc14

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/components/LeetCode.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { useEffect, useState } from 'react';
22
import { getProfile, getStatistics } from '../services/leetcode';
3-
import { LeetCodeProfile } from '../types/leetcode';
3+
import { LeetCodeProfile, LeetCodeStatistics } from '../types/leetcode';
4+
import Profile from './Profile';
45

56
const LeetCode = () => {
67
const [profile, setProfile] = useState<LeetCodeProfile | null>(null);
8+
const [_statistics, setStatistics] = useState<LeetCodeStatistics | null>(null);
79

810
useEffect(() => {
911
getProfile().then(profile => {
@@ -20,20 +22,11 @@ const LeetCode = () => {
2022
return;
2123
}
2224
getStatistics(profile.username).then(d => {
23-
console.log('LeetCode Statistics:', d);
25+
setStatistics(d);
2426
});
2527
}, [profile]);
2628

27-
return profile ? (
28-
<div>
29-
<p>Welcome {profile.username}</p>
30-
<img
31-
src={profile.avatar}
32-
alt="Avatar"
33-
style={{ width: '100px', height: '100px' }}
34-
/>
35-
</div>
36-
) : null;
29+
return profile ? <Profile profile={profile} /> : null;
3730
};
3831

3932
export default LeetCode;

src/components/Profile.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { LeetCodeProfile } from '../types/leetcode';
3+
4+
const Profile = ({ profile }: { profile: LeetCodeProfile }) => {
5+
return (
6+
<div>
7+
<p>Welcome {profile.username}</p>
8+
<img
9+
src={profile.avatar}
10+
alt="Avatar"
11+
style={{ width: '100px', height: '100px' }}
12+
/>
13+
</div>
14+
);
15+
};
16+
17+
export default Profile;

0 commit comments

Comments
 (0)