Skip to content

Commit 1e80359

Browse files
authored
Merge pull request #32 from druvkotwani/fix/leetboard
Fix/leetboard
2 parents e7469e4 + de9c45d commit 1e80359

File tree

4 files changed

+83
-81
lines changed

4 files changed

+83
-81
lines changed

client/src/app/components/Card.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@ import SocialLinks from "./SocialLinks";
55

66
export const data = {
77
profileData: {
8+
username: "druv_kotwani",
9+
rank: 263817,
810
image: "https://assets.leetcode.com/users/avatars/avatar_1672478903.png",
9-
fullName: "John Doe",
10-
username: "johndoe",
11-
rank: "203432",
11+
fullName: "Dhruv Kotwani",
1212
},
1313
aboutData: {
14-
github: { link: "https://github.com/druvkotwani", text: "druvkotwani" },
15-
twitter: { link: "https://twitter.com/druv_kotwani", text: "druv_kotwani" },
14+
github: {
15+
link: "https://github.com/druvkotwani",
16+
text: "Github",
17+
},
18+
website: {
19+
link: "https://dhruvkotwani.vercel.app",
20+
text: "Website",
21+
},
1622
linkedin: {
1723
link: "https://linkedin.com/in/dhruv-kotwani",
18-
text: "dhruv-kotwani",
24+
text: "LinkedIn",
1925
},
20-
website: {
21-
link: "https://dhruvkotwani.me",
22-
text: "dhruvkotwani.vercel.app",
26+
twitter: {
27+
link: "https://twitter.com/druv_kotwani",
28+
text: "Twitter",
2329
},
2430
},
25-
26-
totalSolved: 100,
27-
easySolved: 50,
28-
easyTotal: 100,
29-
mediumSolved: 30,
30-
mediumTotal: 50,
31-
hardSolved: 20,
32-
hardTotal: 50,
31+
total: 3247,
32+
easyTotal: 817,
33+
mediumTotal: 1704,
34+
hardTotal: 726,
35+
totalSolved: 306,
36+
easySolved: 175,
37+
mediumSolved: 110,
38+
hardSolved: 21,
3339
};
3440

3541
export default function Card({ userData = data, index }: any) {

client/src/app/components/GenerateStats.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const GenerateStats = ({ showStats, setShowStats }: any) => {
5050
body: JSON.stringify(data),
5151
});
5252
const result = await response.json();
53+
54+
if (!result.success) {
55+
toast("👻 Username already exists in LeetBoard");
56+
return;
57+
}
58+
5359
if (result.success) {
5460
setDatas([...datas, data]);
5561
toast("🥷Data added to the hall of fame");

client/src/app/components/SocialLinks.tsx

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,46 @@ import Image from "next/image";
44
import Link from "next/link";
55
import { useState } from "react";
66
const SocialLinks = ({ result, index }: any) => {
7-
const [hovered, setHovered] = useState<string | null>(null);
8-
const random = Math.floor(Math.random() * 1);
9-
10-
function truncateText(text: any, maxLength: any) {
11-
if (text && text.length > maxLength) {
12-
return text.substring(0, maxLength) + "...";
13-
}
14-
return text;
15-
}
167
return (
17-
<div className="mt-4 mb-2 flex flex-col justify-self-start">
8+
<div className="mt-2 mb-2 grid grid-cols-2 gap-2">
189
{/* <p className="flex">
19-
<iconify-icon icon="carbon:location" width="17" height="19" style={{ color: 'white', marginRight: '5px' }}></iconify-icon>
10+
<iconify-icon icon="carbon:location" width="21" height="23" style={{ color: 'white', marginRight: '5px' }}></iconify-icon>
2011
<span className='text-sm text-[#BDBEC3] '>India</span>
2112
</p> */}
2213
{result?.website?.link && (
2314
<Link
24-
onMouseEnter={() => setHovered("website")}
25-
onMouseLeave={() => setHovered(null)}
2615
target="_blank"
2716
rel="noreferrer"
2817
href={result?.website?.link}
2918
className="flex"
3019
>
3120
<Image
3221
src="/assets/icons/globe.svg"
33-
width={17}
34-
height={19}
22+
width={25}
23+
height={23}
3524
alt="Website"
36-
className="mr-1"
25+
className="mr-1 hover:scale-125 ease-in transition-all transform duration-300 hover:rotate-180"
3726
/>
38-
<span className="text-sm text-[#BDBEC3] ">
39-
<p className={`${hovered === "website" ? "text-[#f7f7f7]" : ""}`}>
40-
{truncateText(result?.website?.text, 10)}
41-
</p>
42-
</span>
4327
</Link>
4428
)}
4529
{result?.github?.link && (
4630
<Link
47-
onMouseEnter={() => setHovered("github")}
48-
onMouseLeave={() => setHovered(null)}
4931
target="_blank"
5032
rel="noreferrer"
5133
href={result?.github?.link}
5234
className="flex"
5335
>
5436
<Image
5537
src="/assets/icons/github.svg"
56-
width={17}
57-
height={19}
38+
width={21}
39+
height={23}
5840
alt="Github"
59-
className="mr-1"
41+
className="mr-1 hover:scale-125 ease-in transition-all transform duration-300 "
6042
/>
61-
<span className="text-sm text-[#BDBEC3] ">
62-
<p className={`${hovered === "github" ? "text-[#f7f7f7]" : ""}`}>
63-
{truncateText(result?.github?.text, 10)}
64-
</p>
65-
</span>
6643
</Link>
6744
)}
6845
{result?.twitter?.link && (
6946
<Link
70-
onMouseEnter={() => setHovered("twitter")}
71-
onMouseLeave={() => setHovered(null)}
7247
target="_blank"
7348
rel="noreferrer"
7449
href={result?.twitter?.link}
@@ -77,21 +52,14 @@ const SocialLinks = ({ result, index }: any) => {
7752
<Image
7853
src="/assets/icons/twitter.svg"
7954
alt="twitter"
80-
width={17}
81-
height={19}
82-
className="mr-1"
55+
width={21}
56+
height={23}
57+
className="mr-1 hover:scale-125 ease-in transition-all transform duration-300 "
8358
/>
84-
<span className="text-sm text-[#BDBEC3] ">
85-
<p className={`${hovered === "twitter" ? "text-[#f7f7f7]" : ""}`}>
86-
{truncateText(result?.twitter?.text, 10)}
87-
</p>
88-
</span>
8959
</Link>
9060
)}
9161
{result?.linkedin?.link && (
9262
<Link
93-
onMouseEnter={() => setHovered("linkedin")}
94-
onMouseLeave={() => setHovered(null)}
9563
target="_blank"
9664
rel="noreferrer"
9765
href={result?.linkedin?.link}
@@ -100,15 +68,10 @@ const SocialLinks = ({ result, index }: any) => {
10068
<Image
10169
src="/assets/icons/linkedin.svg"
10270
alt="linkedin"
103-
width={17}
104-
height={19}
105-
className="mr-1"
71+
width={21}
72+
height={23}
73+
className="mr-1 hover:scale-125 ease-in transition-all transform duration-300 "
10674
/>
107-
<span className="text-sm text-[#BDBEC3] ">
108-
<p className={`${hovered === "linkedin" ? "text-[#f7f7f7]" : ""}`}>
109-
{truncateText(result?.linkedin?.text, 10)}
110-
</p>
111-
</span>
11275
</Link>
11376
)}
11477
</div>

client/src/app/page.tsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Navbar from "./components/Navbar";
55
import Card from "./components/Card";
66
import Footer from "./components/Footer";
77
import GenerateStats from "./components/GenerateStats";
8-
import { useContext, useEffect, useState } from "react";
8+
import { use, useContext, useEffect, useState } from "react";
99
import PromotionCard from "./components/PromotionCard";
1010
import { DataContext } from "./context/DataContext";
1111
import { ToastContainer } from "react-toastify";
@@ -17,13 +17,13 @@ export default function Home() {
1717
const [loading, setLoading] = useState(true);
1818
const [search, setSearch] = useState<string>("");
1919
const [showStats, setShowStats] = useState(false);
20+
const [sortBy, setSortBy] = useState("default");
2021

2122
const fetchData = async () => {
2223
try {
2324
const res = await fetch("/api/fetchdata");
2425
const data = await res.json();
2526
setDatas(data.data);
26-
console.log(data.data);
2727
setLoading(false);
2828
} catch (error) {
2929
console.error("Error fetching messages:", error);
@@ -34,9 +34,32 @@ export default function Home() {
3434
fetchData();
3535
}, [datas && datas.length]);
3636

37+
useEffect(() => {
38+
setTimeout(() => {
39+
setShowStats(true);
40+
}, 5000);
41+
}, []);
42+
43+
const handleSortChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
44+
setSortBy(e.target.value);
45+
};
46+
3747
const searchedData = datas?.filter((data: any) =>
3848
data.profileData.fullName.toLowerCase().includes(search.toLowerCase())
3949
);
50+
const sorting = (data: any[]) => {
51+
switch (sortBy) {
52+
case "question-solved":
53+
return data.slice().sort((a, b) => b.totalSolved - a.totalSolved);
54+
case "default":
55+
default:
56+
return data.slice().sort((a, b) => {
57+
return (
58+
new Date(b.timeStamp).getTime() - new Date(a.timeStamp).getTime()
59+
);
60+
});
61+
}
62+
};
4063

4164
return (
4265
<section className="px-4 lg:px-24 relative ">
@@ -56,7 +79,18 @@ export default function Home() {
5679

5780
<GenerateStats showStats={showStats} setShowStats={setShowStats} />
5881

59-
<div className="mt-32 max-w-7xl mx-auto place-items-center grid grid-cols-1 md:grid-cols-2 gap-y-8 xl:grid-cols-3 font-sourcecodepro gap-x-4">
82+
<div className="w-full flex items-center justify-center ">
83+
<select
84+
value={sortBy}
85+
onChange={handleSortChange}
86+
className="mt-28 rounded border-2 border-[#f7f7f7] w-64 bg-[#0e0e0e] text-white p-2 font-sourcecodepro"
87+
>
88+
<option value="default">Sort By Default</option>
89+
<option value="question-solved">Sort By Questions Solved</option>
90+
</select>
91+
</div>
92+
93+
<div className="mt-8 max-w-7xl mx-auto place-items-center grid grid-cols-1 md:grid-cols-2 gap-y-8 xl:grid-cols-3 font-sourcecodepro gap-x-4">
6094
<PromotionCard />
6195
{loading ? (
6296
<>
@@ -65,16 +99,9 @@ export default function Home() {
6599
))}
66100
</>
67101
) : (
68-
searchedData &&
69-
searchedData
70-
.sort(
71-
(a: any, b: any) =>
72-
new Date(b.timeStamp).getTime() -
73-
new Date(a.timeStamp).getTime()
74-
)
75-
.map((userData: any, index: number) => (
76-
<Card userData={userData} index={index} key={index} />
77-
))
102+
sorting(searchedData).map((userData: any, index: number) => (
103+
<Card userData={userData} index={index} key={index} />
104+
))
78105
)}
79106
</div>
80107

0 commit comments

Comments
 (0)