Fixed some bugs related to POTD page#174
Conversation
|
@aviralsaxena16 is attempting to deploy a commit to the aviralsaxena16's projects Team on Vercel. A member of the Team first needs to authorize it. |
🎉 Thanks for Your Contribution to CanonForces!
|
|
Warning Review limit reached
More reviews will be available in 40 minutes and 55 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe POTD page is refactored to use React state for current user auth status, backfill daily submission data when missing, throw errors on invalid verification, and restructure mission header and action UI to display stats and verification controls with updated sidebar empty-state messages. ChangesPOTD Page Auth State and Verification Flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pages/potd.tsx`:
- Around line 233-239: checkCodeforcesSubmission currently returns true for any
historical AC, letting users claim today's POTD; update the verification to
require an accepted submission timestamp within the target day before awarding
and messaging. Modify checkCodeforcesSubmission (or create a new helper like
checkCodeforcesSubmissionOnDate) to fetch the user's submissions for the
contest/problem and confirm at least one accepted submission whose
epoch/timezone-normalized date equals the POTD date (use startOfDay/endOfDay
bounds in the app's timezone or UTC as appropriate), then call markAsSolved and
show the success toast only when that date-limited check passes; also adjust the
success/error messages to accurately reflect "found today" vs historical ACs.
- Around line 187-190: The fallback for resolvedUsername can produce an array
because currentUser.email.split("@") returns string[]; change the fallback to
produce a string (e.g., use currentUser.email?.split("@")[0] or another
string-safe expression) so resolvedUsername is always a string; update the
assignment that uses userData.username, currentUser.displayName, and
currentUser.email to ensure resolvedUsername is a string before writing into
solvers[uid].username and downstream uses.
- Around line 174-176: The early-return when currentUserData.lastSolvedDate ===
todayDate should throw an error instead so the transaction resolves as a
rejection and the caller (handleCheckCFSubmission) won't display the success
toast; replace the return with a thrown Error (or custom error type/message like
"Already solved today") in the function where currentUserData and lastSolvedDate
are checked, ensure callers (handleCheckCFSubmission and any callers of
markAsSolved) catch this error and handle it without showing the "progress
saved" toast.
- Around line 145-157: When currentUser becomes null the effect returns early
but doesn't clear derived state; update the effect to explicitly reset
setUserData and setCfUsername to their signed-out defaults when currentUser is
falsy (e.g. setUserData({coins: 0, streak: 0, lastSolvedDate: null, username:
""}) and setCfUsername("")), then return; otherwise proceed to create the
userRef, subscribe via onSnapshot and return the unsubscribe; ensure you
reference currentUser, setUserData, setCfUsername and the onSnapshot/unsubscribe
logic in the change.
- Line 295: The code renders untrusted Firestore content via
dangerouslySetInnerHTML using formatDescription(fullDesc) without sanitization;
update the rendering pipeline to sanitize or escape input before passing it to
dangerouslySetInnerHTML — for example, import a sanitizer like DOMPurify (or
sanitize-html), run DOMPurify.sanitize(...) on the raw problem.description (or
on the HTML produced by formatDescription) with an explicit
allowedTags/allowedAttributes policy, and then use the sanitized string in the
div (the symbols to change are formatDescription, fullDesc, and the JSX div with
dangerouslySetInnerHTML); ensure you do not call dangerouslySetInnerHTML with
unsanitized user content and add unit/CI checks if available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| const hasSolved = await checkCodeforcesSubmission(usernameToCheck, contestId, problemIndex); | ||
|
|
||
| if (hasSolved) { | ||
| await markAsSolved(); // If this fails, it jumps to the catch block and WON'T show success | ||
| toast.success("🎉 Verified! Solution found and progress saved!"); | ||
| } else { | ||
| toast.error("No accepted submission found today."); |
There was a problem hiding this comment.
Verification still accepts historical Codeforces ACs.
This branch awards today's streak/coins based on checkCodeforcesSubmission(), but that helper only checks whether the user has ever AC'd the contest/problem. A user with an old accepted submission can still claim today's POTD, and the “found today” messaging is inaccurate.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/potd.tsx` around lines 233 - 239, checkCodeforcesSubmission
currently returns true for any historical AC, letting users claim today's POTD;
update the verification to require an accepted submission timestamp within the
target day before awarding and messaging. Modify checkCodeforcesSubmission (or
create a new helper like checkCodeforcesSubmissionOnDate) to fetch the user's
submissions for the contest/problem and confirm at least one accepted submission
whose epoch/timezone-normalized date equals the POTD date (use
startOfDay/endOfDay bounds in the app's timezone or UTC as appropriate), then
call markAsSolved and show the success toast only when that date-limited check
passes; also adjust the success/error messages to accurately reflect "found
today" vs historical ACs.
Bugs like streak update failure , coin update failure submission race condition
Summary by CodeRabbit
Bug Fixes
New Features