Skip to content

fix: improve difficulty badge visibility when problem row is selected(hover)#158

Merged
kunalverma2512 merged 2 commits into
kunalverma2512:mainfrom
kalsariyaarpan:fix/difficulty-badge-visibility
Jun 4, 2026
Merged

fix: improve difficulty badge visibility when problem row is selected(hover)#158
kunalverma2512 merged 2 commits into
kunalverma2512:mainfrom
kalsariyaarpan:fix/difficulty-badge-visibility

Conversation

@kalsariyaarpan

@kalsariyaarpan kalsariyaarpan commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

closes #156
Fixes the difficulty badge visibility issue when a problem row is highlighted (hovered).

Previously, when a row background changed to a dark color on hover, difficulty badges could become difficult to read due to insufficient contrast. This update ensures that badge text and borders remain clearly visible during the hover state.

Changes Made

  • Added hover styles for difficulty badges.
  • Improved text and border visibility on dark row backgrounds.
  • Maintained existing layout and badge structure.
  • No functional changes to problem navigation or page behavior.

Testing

Verified visibility for all difficulty levels:

  • Beginner
  • Easy
  • Medium
  • Hard
  • Expert
  • Unrated

Confirmed that badges remain readable when a problem row is hovered and that no visual regressions were introduced.

Before

602203843-728ecc0d-3dab-4992-a1bd-5572504f4212

After

Screenshot 2026-06-04 163705 Screenshot 2026-06-04 163730 Screenshot 2026-06-04 163749

Summary by CodeRabbit

  • Style
    • Improved responsive layout of difficulty badges on the practice page with refined styling and spacing adjustments.

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

@kalsariyaarpan is attempting to deploy a commit to the Kunal Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🚀 PR Received Successfully

Hello @kalsariyaarpan,

Thank you for taking the initiative to contribute to this project.

Please ensure that your PR follows all project guidelines properly before requesting review.

⚠️ Important Instructions

  • Maintain proper code quality and structure
  • Do not make unnecessary changes/files
  • Ensure responsiveness across devices
  • Follow existing project conventions strictly
  • Attach screenshots/videos for UI-related changes
  • Resolve merge conflicts before requesting review
  • Avoid AI-generated low quality PRs or copied implementations

📌 Mandatory for GSSoC'26 Participants

Joining the community group and announcement channel is compulsory for all contributors participating through GSSoC'26.

Failure to follow contribution guidelines may lead to PR rejection.

We appreciate your effort and wish you a great open-source journey ahead. ✨

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b8217b4-2384-43d3-909b-fe9c886bd27c

📥 Commits

Reviewing files that changed from the base of the PR and between bb5696c and abbccd8.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • frontend/src/pages/PracticePage.jsx

📝 Walkthrough

Walkthrough

The PR refactors the difficulty badge rendering in the ProblemRow component, adjusting the wrapper and badge span classes for improved responsive styling while preserving the difficulty label text and color-driven classes.

Changes

Difficulty Badge UI Refactor

Layer / File(s) Summary
Difficulty badge styling
frontend/src/pages/PracticePage.jsx
The difficulty badge's wrapper span and nested badge element classes were refactored, adjusting responsive sizing behavior such as w-20 and hidden lg:block, while the computed diffLabel text and diffCls color classes remain unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Poem

🐰 A badge gets dressed in new Tailwind threads,
Responsive and clean, no more dread,
The label stays true, the colors align,
A smaller refactor, but oh how they shine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving difficulty badge visibility during hover states, which directly aligns with the refactoring of the difficulty badge section in ProblemRow.
Description check ✅ Passed The description covers all essential sections: problem statement, changes made, testing verification, and visual demonstrations; it follows the template structure with related content throughout.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kunalverma2512

Copy link
Copy Markdown
Owner

@coderabbitai please check is this PR ready to merge ? and the work done in this PR is compatible to rest nearby codes
check responsiveness

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the full PracticePage.jsx content on PR branch
cat frontend/src/pages/PracticePage.jsx

Length of output: 29029


🏁 Script executed:

#!/bin/bash
# Get the git diff for this PR
git diff origin/main...HEAD -- frontend/src/pages/PracticePage.jsx

Length of output: 1223



The PR description images show:

  • Before (Image 1): The LEVEL badge is invisible/blank when the row is hovered (dark background), because group-hover:bg-transparent made the badge transparent while light-colored text became unreadable against the black row.
  • After (Images 2–4): BEGINNER, UNRATED, HARD badges all show clearly with white text and white border on the dark hover background.

@kunalverma2512 Here is the full assessment:

✅ Fix Correctness

The core bug fix is correct. The old code had group-hover:bg-transparent on the badge, which caused it to blend into the dark hovered row. The replacement (group-hover:text-white, group-hover:bg-black, group-hover:border-white) works for all difficulty levels:

Level Default diffCls On hover (new)
Beginner bg-gray-100 text-black bg-black text-white border-white ✅
Easy/Hard/Expert bg-black text-white bg-black (same), text-white (same), border-white ✅
Unrated text-gray-500 (no bg) bg-black text-white border-white ✅

✅ Responsiveness

No regression. The badge wrapper retains hidden lg:block, which matches the table header's Level column (hidden lg:block). On screens < 1024 px, both header and badge are hidden — consistent and intentional.

⚠️ Minor Issues to Address Before Merging

1. Formatting regression in the diff — Extra blank lines and inconsistent indentation were introduced. The rest of ProblemRow uses 6-space indentation, but the badge section now drifts to 4-space with 2 extra blank lines above it:

// Clean this up to match the rest of the component:
{/* Difficulty badge */}
<span className="w-20 text-center flex-shrink-0 hidden lg:block">
  <span
    className={`text-[10px] font-black uppercase tracking-widest border-2 px-2 py-0.5
      group-hover:text-white group-hover:bg-black group-hover:border-white ${diffCls}`}
  >
    {diffLabel}
  </span>
</span>

🐛 Pre-existing Bug (not introduced by this PR)

The clearAll function calls setDebouncedSearch("") but debouncedSearch is read-only state from the useDebounce hook — this will throw a runtime error when Clear All is clicked. This should be fixed in a follow-up. Would you like me to open an issue for it?


Summary: The PR is nearly ready to merge — the fix is correct and doesn't break responsiveness or compatibility. The only blocker is the indentation/formatting cleanup in the changed section. Once that's tidied, it's good to go. 🐇

@kunalverma2512

Copy link
Copy Markdown
Owner

@coderabbitai you are correct about that pre-existing bug and just now I visited the page and tried to click on clear and I got an error in browser console :
index-CyhY7F8s.js:105 Uncaught ReferenceError: setDebouncedSearch is not defined
at N (index-CyhY7F8s.js:105:54932)
at Td (index-CyhY7F8s.js:8:126341)
at index-CyhY7F8s.js:8:131334
at un (index-CyhY7F8s.js:8:15081)
at Ad (index-CyhY7F8s.js:8:127568)
at _p (index-CyhY7F8s.js:9:28475)
at hp (index-CyhY7F8s.js:9:28297)

So please make a separate issue for this bug and make sure you describe the problem in detail so that contributors can understand and learn in deep about this and make use of this error got in browser console that I pasted above

and some more stuff as you like

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Extract the clearAll function and useDebounce/debouncedSearch usage
rg -n "clearAll|debouncedSearch|useDebounce|setDebouncedSearch" frontend/src/pages/PracticePage.jsx -A 3 -B 1

Length of output: 2617


🏁 Script executed:

#!/bin/bash
gh issue create \
  --repo kunalverma2512/CodeLens \
  --title "bug: ReferenceError: setDebouncedSearch is not defined when clicking 'Clear All' on Practice Page" \
  --body "## Bug Report

**Reported by:** `@kunalverma2512`
**Related PR:** https://github.com/kunalverma2512/CodeLens/pull/158#issuecomment-$(date +%s)

---

## Summary

Clicking the **\"Clear All\"** button (or **\"Clear All Filters\"** button) on the Practice Page crashes with a \`ReferenceError\` in the browser console. The page becomes unresponsive to filter clearing.

---

## Browser Console Error

\`\`\`
index-CyhY7F8s.js:105 Uncaught ReferenceError: setDebouncedSearch is not defined
    at N (index-CyhY7F8s.js:105:54932)
    at Td (index-CyhY7F8s.js:8:126341)
    at index-CyhY7F8s.js:8:131334
    at un (index-CyhY7F8s.js:8:15081)
    at Ad (index-CyhY7F8s.js:8:127568)
    at _p (index-CyhY7F8s.js:9:28475)
    at hp (index-CyhY7F8s.js:9:28297)
\`\`\`

---

## Steps to Reproduce

1. Go to the **Practice Page** (the page listing Codeforces problems).
2. Type something in the search box, or select a tag/rating filter.
3. Click the **\"Clear All\"** button that appears in the active filter chips area, or click **\"Clear All Filters\"** in the no-results state.
4. Observe the \`ReferenceError\` in the browser DevTools console (F12 → Console tab).

---

## Root Cause (Technical Explanation for Contributors)

**File:** \`frontend/src/pages/PracticePage.jsx\`

The \`useDebounce\` hook is used to delay the search query update so that the problems list does not re-filter on every single keystroke:

\`\`\`js
// Line 203
const debouncedSearch = useDebounce(searchQuery, 300);
\`\`\`

The \`useDebounce\` hook returns **only the debounced value** — it does not expose a setter function. This is the standard pattern for debounce hooks in React: you own the source state (\`searchQuery\` / \`setSearchQuery\`), and the hook derives a delayed read-only copy from it.

However, the \`clearAll\` function (around line 333) incorrectly tries to call a non-existent \`setDebouncedSearch\` setter:

\`\`\`js
const clearAll = () => {
  setSearchQuery(\"\");       // ✅ Correct — resets the source state
  setDebouncedSearch(\"\");   // ❌ Bug — this function does not exist anywhere!
  setSelectedTags([]);
  setRatingIdx(0);
  setSortBy(\"rating-asc\");
};
\`\`\`

Because \`setDebouncedSearch\` is never declared or imported, JavaScript throws a \`ReferenceError\` the moment \`clearAll\` is invoked — preventing any of the reset logic below it from executing.

---

## Why Does the Filter Look Like It Doesn't Clear Immediately?

When \`setSearchQuery(\"\")\` is called, the debounce timer starts. After 300 ms, \`debouncedSearch\` will automatically become \`\"\"\` and the problem list will re-filter correctly. So the manual \`setDebouncedSearch(\"\")\` call was likely added in an attempt to make the clear feel instant — but since the function doesn't exist, it breaks everything instead.

---

## Suggested Fix

Simply remove the invalid \`setDebouncedSearch(\"\")\` call from the \`clearAll\` function. Resetting \`searchQuery\` via \`setSearchQuery(\"\")\` is sufficient; \`debouncedSearch\` will follow automatically within 300 ms:

\`\`\`js
const clearAll = () => {
  setSearchQuery(\"\");
  // Remove: setDebouncedSearch(\"\");  ← this line causes the crash
  setSelectedTags([]);
  setRatingIdx(0);
  setSortBy(\"rating-asc\");
};
\`\`\`

If an **instant** (zero-delay) clear is preferred UX-wise, the \`useDebounce\` hook (\`frontend/src/hooks/useDebounce.js\`) can be extended to return a \`[debouncedValue, setValue]\` tuple — similar to how \`useState\` works — so callers can manually override the debounced value when needed.

---

## Affected Buttons

There are **two** buttons that both call \`clearAll\`:
1. The inline **\"Clear All\"** chip that appears next to active filter badges (line ~515).
2. The **\"Clear All Filters\"** button shown in the empty-results state (line ~570).

Both are broken by this bug.

---

## Environment

- **File:** \`frontend/src/pages/PracticePage.jsx\`
- **Hook:** \`frontend/src/hooks/useDebounce.js\` (or \`.ts\`)
- **Framework:** React (Vite build, minified output \`index-CyhY7F8s.js\`)

---

## Acceptance Criteria

- [ ] Clicking \"Clear All\" clears search, tags, rating, and sort without any console errors.
- [ ] The problems list resets correctly after clearing.
- [ ] No regression to the debounce behaviour during normal typing."

Length of output: 4582



@kunalverma2512 Done! I've created a detailed issue here: #161

Here's what's included in it to help contributors:

  • 📋 Exact browser console error you pasted
  • 🔍 Steps to reproduce (both "Clear All" and "Clear All Filters" buttons are affected)
  • 🧠 Deep technical explanation of why this crashes — how useDebounce works, why it returns a read-only value, and why setDebouncedSearch was never valid
  • 🔧 Suggested fix — simply remove the setDebouncedSearch("") line from clearAll (setting searchQuery via setSearchQuery("") is sufficient; debouncedSearch follows automatically after the 300 ms debounce delay)
  • 💡 Alternative approach — if instant clearing is desired UX-wise, extend the useDebounce hook to return a [value, setValue] tuple
  • Acceptance criteria checklist so contributors know exactly what done looks like

(╯°□°)╯ bugs beware — good catch confirming this in the browser!

@kunalverma2512 kunalverma2512 self-assigned this Jun 4, 2026
@kunalverma2512 kunalverma2512 merged commit bb710dd into kunalverma2512:main Jun 4, 2026
2 of 3 checks passed
@kunalverma2512

Copy link
Copy Markdown
Owner

@kalsariyaarpan this time I have merged the PR but make sure to write issue no
Its bad to have such description
follow the PR template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Difficulty Badge Becomes Invisible When Problem Row Is Selected

2 participants