|
1 | 1 | import Questions from "./Questions"; |
2 | 2 | import Circle from "./Circle"; |
3 | | -import { useState } from "react"; |
| 3 | +import { useState, useEffect } from "react"; |
4 | 4 | import Profile from "./Profile"; |
5 | 5 | import About from "./About"; |
6 | 6 |
|
7 | | -export default function Stat() { |
| 7 | +export default function Stat({ data }) { |
| 8 | + const [userData, setUserData] = useState({}); |
8 | 9 |
|
9 | | - const defaultProfileData = { |
10 | | - image: '/assets/profile.png', |
11 | | - fullName: 'Dhruv Kotwani', |
12 | | - username: 'druv_kotwani', |
13 | | - badgeImg: '/assets/badge.png', |
14 | | - rank: '234, 542', |
15 | | - }; |
| 10 | + const setDataManually = () => { |
| 11 | + const newProfileData = { |
| 12 | + fullName: data.fullName, |
| 13 | + image: data.image, |
| 14 | + badgeImg: data.badgeImg, |
| 15 | + username: data.username, |
| 16 | + rank: data.rank, |
| 17 | + }; |
16 | 18 |
|
17 | | - let defaultAboutUs = { |
18 | | - linkedin: { link: "https://linkedin.com/in/dhruv-kotwani", text: "dhruv-kotwani" }, |
19 | | - twitter: { link: "https://twitter.com/druv_kotwani", text: "druv_kotwani" }, |
20 | | - github: { link: "https://github.com/druvkotwani", text: "druvkotwani" }, |
21 | | - website: { link: "https://dhruvkotwani.me", text: "dhruvkotwani.me" } |
22 | | - }; |
23 | | - const defaultQuestionData = { |
24 | | - easySolved: 165, |
25 | | - easyTotal: 745, |
26 | | - easyBeats: '96.9%', |
27 | | - mediumSolved: 92, |
28 | | - mediumTotal: 1547, |
29 | | - mediumBeats: '84.8%', |
30 | | - hardSolved: 20, |
31 | | - hardTotal: 644, |
32 | | - hardBeats: '77.6%', |
33 | | - totalSolved: 277, |
34 | | - totalQuestions: 2940, |
35 | | - }; |
| 19 | + const newQuestionData = { |
| 20 | + easySolved: data.easySolved, |
| 21 | + easyTotal: data.easyTotal, |
| 22 | + easyBeats: data.easyBeats, |
| 23 | + mediumSolved: data.mediumSolved, |
| 24 | + mediumTotal: data.mediumTotal, |
| 25 | + mediumBeats: data.mediumBeats, |
| 26 | + hardSolved: data.hardSolved, |
| 27 | + hardTotal: data.hardTotal, |
| 28 | + hardBeats: data.hardBeats, |
| 29 | + totalSolved: data.totalSolved, |
| 30 | + totalQuestions: data.totalQuestions, |
| 31 | + }; |
| 32 | + |
| 33 | + const newAboutData = { |
| 34 | + linkedin: data.linkedin, |
| 35 | + twitter: data.twitter, |
| 36 | + github: data.github, |
| 37 | + website: data.website, |
| 38 | + // Add other about data fields as needed |
| 39 | + } |
| 40 | + setUserData({ |
| 41 | + profileData: newProfileData, |
| 42 | + questionData: newQuestionData, |
| 43 | + aboutData: newAboutData, |
| 44 | + }); |
| 45 | + } |
| 46 | + useEffect(() => { |
| 47 | + if (data) { |
| 48 | + setDataManually(data); |
| 49 | + } |
| 50 | + }, [data]); |
36 | 51 |
|
37 | | - const [userData, setUserData] = useState({ |
38 | | - profileData: defaultProfileData, |
39 | | - questionData: defaultQuestionData, |
40 | | - aboutData: defaultAboutUs, |
41 | | - }); |
42 | 52 |
|
43 | 53 |
|
44 | 54 | return ( |
45 | 55 | <div className="flex justify-center flex-col items-center rounded-lg h-[280px] bg-[#292829]"> |
46 | 56 | <div> |
47 | | - <div className="flex gap-1 xl:gap-4 items-center justify-center "> |
48 | | - <Profile userData={userData} /> |
49 | | - <About result={userData.aboutData} /> |
| 57 | + <div className="flex gap-1 xl:gap-4 items-center justify-between "> |
| 58 | + <Profile userData={userData?.profileData} /> |
| 59 | + <About result={userData?.aboutData} /> |
50 | 60 | </div> |
51 | 61 | <div style={{ height: '0.5px', backgroundColor: '#E0E0E0' }} className="h-[0.5px] bg-white" /> |
52 | 62 | <div className=" flex lg:flex-row gap-5 items-center justify-center mt-4"> |
53 | | - <Circle total={userData?.questionData?.totalSolved} /> |
| 63 | + <Circle total={data?.totalSolved} /> |
54 | 64 | <div className="flex flex-col gap-3"> |
55 | 65 | <Questions |
56 | 66 | type={'Easy'} |
57 | | - solved={userData?.questionData?.easySolved} |
58 | | - total={userData?.questionData?.easyTotal} |
59 | | - beats={userData?.questionData?.easyBeats} |
| 67 | + solved={data?.easySolved} |
| 68 | + total={data?.easyTotal} |
| 69 | + beats={data?.easyBeats} |
60 | 70 | line='bg-[#2db55d26]' |
61 | 71 | line2='bg-[#01B8A2]' |
62 | 72 | /> |
63 | 73 | <Questions |
64 | 74 | type={'Medium'} |
65 | | - solved={userData?.questionData?.mediumSolved} |
66 | | - total={userData?.questionData?.mediumTotal} |
67 | | - beats={userData?.questionData?.mediumBeats} |
| 75 | + solved={data?.mediumSolved} |
| 76 | + total={data?.mediumTotal} |
| 77 | + beats={data?.mediumBeats} |
68 | 78 | line='bg-[#ffb80026]' |
69 | 79 | line2='bg-[#FFC11F]' |
70 | 80 | /> |
71 | 81 | <Questions |
72 | 82 | type={'Hard'} |
73 | | - solved={userData?.questionData?.hardSolved} |
74 | | - total={userData?.questionData?.hardTotal} |
75 | | - beats={userData?.questionData?.hardBeats} |
| 83 | + solved={data?.hardSolved} |
| 84 | + total={data?.hardTotal} |
| 85 | + beats={data?.hardBeats} |
76 | 86 | line='bg-[#ef474326]' |
77 | 87 | line2='bg-[#EF4642]' |
78 | 88 | /> |
|
0 commit comments