Skip to content

Commit 2b31073

Browse files
committed
feat: add leetcode problem search and filters
1 parent ecc732f commit 2b31073

2 files changed

Lines changed: 77 additions & 17 deletions

File tree

src/problems/leetcode/LeetCodeProblems.jsx

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
import React, { useEffect, useState } from "react";
22
import { recentSolved } from "./recentSolved";
33

4-
const LEETCODE_USERNAME = "Sunil-Kumar-K-V";
4+
const LEETCODE_USERNAME = "YOUR_LEETCODE_USERNAME";
55

66
export default function LeetCodeProblems() {
77
const [stats, setStats] = useState(null);
8+
const [query, setQuery] = useState("");
9+
const [difficulty, setDifficulty] = useState("All");
810

911
useEffect(() => {
1012
fetch(`https://leetcode-stats-api.herokuapp.com/${LEETCODE_USERNAME}`)
1113
.then((res) => res.json())
1214
.then(setStats)
1315
.catch(console.error);
1416
}, []);
15-
16-
<section className="section-panel">
17-
<span className="section-eyebrow">Recent Practice</span>
18-
<h2>Recently Solved Problems</h2>
1917

20-
<div className="feature-grid">
21-
{recentSolved.map((problem) => (
22-
<article className="glass-card" key={problem.title}>
23-
<h3>{problem.title}</h3>
24-
<p>{problem.platform}{problem.difficulty}</p>
25-
<a href={problem.url} target="_blank" rel="noreferrer">
26-
View Problem →
27-
</a>
28-
</article>
29-
))}
30-
</div>
31-
</section>
18+
const filteredProblems = recentSolved.filter((problem) => {
19+
const matchesSearch = problem.title
20+
.toLowerCase()
21+
.includes(query.toLowerCase());
22+
23+
const matchesDifficulty =
24+
difficulty === "All" || problem.difficulty === difficulty;
25+
26+
return matchesSearch && matchesDifficulty;
27+
});
3228

3329
return (
3430
<main className="page-shell">
@@ -66,6 +62,58 @@ export default function LeetCodeProblems() {
6662
<p>Advanced problem-solving challenges.</p>
6763
</article>
6864
</div>
65+
66+
<section className="section-panel">
67+
<span className="section-eyebrow">Recent Practice</span>
68+
<h2>Recently Solved Problems</h2>
69+
70+
<div className="problem-grid">
71+
<input
72+
type="text"
73+
placeholder="Search problems..."
74+
value={query}
75+
onChange={(e) => setQuery(e.target.value)}
76+
style={{
77+
padding: "14px",
78+
borderRadius: "12px",
79+
border: "1px solid rgba(255,255,255,0.2)",
80+
background: "transparent",
81+
color: "inherit",
82+
}}
83+
/>
84+
85+
<select
86+
value={difficulty}
87+
onChange={(e) => setDifficulty(e.target.value)}
88+
style={{
89+
padding: "14px",
90+
borderRadius: "12px",
91+
border: "1px solid rgba(255,255,255,0.2)",
92+
background: "transparent",
93+
color: "inherit",
94+
}}
95+
>
96+
<option>All</option>
97+
<option>Easy</option>
98+
<option>Medium</option>
99+
<option>Hard</option>
100+
</select>
101+
</div>
102+
103+
<div className="feature-grid">
104+
{filteredProblems.map((problem) => (
105+
<article className="glass-card" key={problem.title}>
106+
<h3>{problem.title}</h3>
107+
<p>
108+
{problem.platform}{problem.difficulty}
109+
</p>
110+
<a href={problem.url} target="_blank" rel="noreferrer">
111+
View Problem →
112+
</a>
113+
</article>
114+
))}
115+
</div>
116+
</section>
69117
</main>
70118
);
71119
}

src/problems/leetcode/recentSolved.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ export const recentSolved = [
55
platform: "LeetCode",
66
url: "https://leetcode.com/problems/two-sum/",
77
},
8+
{
9+
title: "Valid Parentheses",
10+
difficulty: "Easy",
11+
platform: "LeetCode",
12+
url: "https://leetcode.com/problems/valid-parentheses/",
13+
},
14+
{
15+
title: "Add Two Numbers",
16+
difficulty: "Medium",
17+
platform: "LeetCode",
18+
url: "https://leetcode.com/problems/add-two-numbers/",
19+
},
820
];

0 commit comments

Comments
 (0)