Skip to content

feat: centralize XP magic numbers in config file with shared level formula#47

Merged
Rishabhworkspace merged 3 commits into
Rishabhworkspace:mainfrom
arcgod-design:feat/issue-21-config-file
Jun 23, 2026
Merged

feat: centralize XP magic numbers in config file with shared level formula#47
Rishabhworkspace merged 3 commits into
Rishabhworkspace:mainfrom
arcgod-design:feat/issue-21-config-file

Conversation

@arcgod-design

@arcgod-design arcgod-design commented Jun 18, 2026

Copy link
Copy Markdown

Summary

  • Created centralized XP config file with named constants (SOLVE_XP, XP_PER_LEVEL)
  • Added shared calculateLevel() utility used by both frontend and backend
  • Replaced all hardcoded magic numbers across 7 files
  • Added user-facing tooltip on Dashboard XP card explaining the leveling system

Changes

  • backend/src/config/xpConfig.ts: New config file with SOLVE_XP = 25, XP_PER_LEVEL = 1000, and calculateLevel() function
  • app/src/utils/xpConfig.ts: Frontend copy of the same config for shared consistency
  • backend/src/controllers/userActionController.ts: Replaced increment: 25 / decrement: 25 with SOLVE_XP
  • backend/src/controllers/userController.ts: Replaced inline level formula with calculateLevel()
  • app/src/sections/Dashboard.tsx: Uses SOLVE_XP, XP_PER_LEVEL, calculateLevel(); XP card has tooltip: "Earn 25 XP per solved problem. Every 1,000 XP = 1 Level."
  • app/src/sections/DailyChallenges.tsx: Uses SOLVE_XP in toast and XP labels
  • app/src/sections/TopicDetail.tsx: Uses SOLVE_XP in toast
  • app/src/sections/Problems.tsx: Uses SOLVE_XP in toast

Files Modified

File Change
backend/src/config/xpConfig.ts NEW — centralized constants + utility
app/src/utils/xpConfig.ts NEW — frontend copy
backend/src/controllers/userActionController.ts SOLVE_XP replaces 25
backend/src/controllers/userController.ts calculateLevel() replaces inline formula
app/src/sections/Dashboard.tsx SOLVE_XP, XP_PER_LEVEL, calculateLevel(), tooltip
app/src/sections/DailyChallenges.tsx SOLVE_XP in toast/labels
app/src/sections/TopicDetail.tsx SOLVE_XP in toast
app/src/sections/Problems.tsx SOLVE_XP in toast

Closes

closes #21

Summary by CodeRabbit

  • New Features
    • Added interactive help tooltips to dashboard stat cards for better clarity on XP and level progression
    • Enhanced accessibility with status indicators and descriptive labels on key dashboard statistics

@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the rishabhjtripathi2903-3434's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 30b85f7b-babc-4c8f-ba85-23f9d17e756c

📥 Commits

Reviewing files that changed from the base of the PR and between c542097 and e14387e.

📒 Files selected for processing (8)
  • app/src/sections/DailyChallenges.tsx
  • app/src/sections/Dashboard.tsx
  • app/src/sections/Problems.tsx
  • app/src/sections/TopicDetail.tsx
  • app/src/utils/xpConfig.ts
  • backend/src/config/xpConfig.ts
  • backend/src/controllers/userActionController.ts
  • backend/src/controllers/userController.ts

📝 Walkthrough

Walkthrough

Two new xpConfig modules are created—one in the frontend (app/src/utils/xpConfig.ts) and one in the backend (backend/src/config/xpConfig.ts)—each exporting SOLVE_XP=25, XP_PER_LEVEL=1000, and a calculateLevel function. All hardcoded XP values (25) and inline level formulas across userActionController, userController, Dashboard, DailyChallenges, Problems, and TopicDetail are replaced with these exports. Dashboard also gains stat card accessibility attributes and a conditional XP tooltip.

Changes

XP Config Centralization

Layer / File(s) Summary
xpConfig contract modules (frontend + backend)
app/src/utils/xpConfig.ts, backend/src/config/xpConfig.ts
New modules each export SOLVE_XP = 25, XP_PER_LEVEL = 1000, and calculateLevel(xpPoints) using Math.floor(xpPoints / XP_PER_LEVEL) + 1.
Backend controllers adopt SOLVE_XP and calculateLevel
backend/src/controllers/userActionController.ts, backend/src/controllers/userController.ts
userActionController replaces hardcoded 25 with SOLVE_XP for both XP increment and decrement. userController replaces the inline level formula with calculateLevel in getUserProfile and updateUserProfile.
Frontend sections adopt SOLVE_XP, calculateLevel, and XP_PER_LEVEL
app/src/sections/DailyChallenges.tsx, app/src/sections/Problems.tsx, app/src/sections/TopicDetail.tsx, app/src/sections/Dashboard.tsx
All four sections replace hardcoded +25 XP strings in solve toasts, header totals, and reward labels with SOLVE_XP. Dashboard additionally uses calculateLevel for displayed level, drives stat card copy from SOLVE_XP/XP_PER_LEVEL, and adds role="status", aria-label, and conditional hover tooltip rendering to each stat card.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 No more magic 25 hiding in the code,
A single SOLVE_XP now lights the XP road.
calculateLevel hops from front to back,
One config file keeps every value on track.
The rabbit counted constants — now just one to change!
✨ Refactored clean, across the whole range. ✨

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.0)
app/src/sections/Dashboard.tsx

File contains syntax errors that prevent linting: Line 426: Expected corresponding JSX closing tag for 'div'.; Line 455: expected } but instead found ); Line 455: Unexpected token. Did you mean {'}'} or &rbrace;?; Line 458: expected ) but instead found {; Line 459: expected , but instead found className; Line 461: expected , but instead found className; Line 464: expected , but instead found initial; Line 464: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '{ opacity'.; Line 464: expected , but instead found :; Line 464: expected , but instead found }; Line 465: expected , but instead found animate; Line 465: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '{ opacity'.; Line 465: expected , but instead found :; Line 465: expected , but instead found }; Line 466: expected , but instead found transition; Line 466: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '{ duration'.; Line 466: expected , but instead found :; Line 466: expected , but instead found }; Line 467: expected , but instead found className; Line 477: expected , but instead found {; Line 478: expected , but instead found className; Line 487: expected , but instead found <; Line 403: Expected corresponding JSX closing tag for 'motion.div'.; Line 307: Expected corresponding JSX closing tag for 'div'.; Line 300: Expected corresponding JSX closing tag for 'section'.; Line 857: expected ) but instead found {; Line 983: Expected an expression but instead found '<'.


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.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
algo-forge-2-0 Ready Ready Preview, Comment Jun 23, 2026 2:31am

@Rishabhworkspace Rishabhworkspace merged commit 92c2f53 into Rishabhworkspace:main Jun 23, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Easy enhancement New feature or request SSoC26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardcoded XP Magic Numbers — Centralize in a Config File

2 participants