fix: give the eco-challenge error screen a way out (#1105) - #1110
Open
MOHITKOURAV01 wants to merge 1 commit into
Open
fix: give the eco-challenge error screen a way out (#1105)#1110MOHITKOURAV01 wants to merge 1 commit into
MOHITKOURAV01 wants to merge 1 commit into
Conversation
setError(null) appeared nowhere, so the first failed load ended the
component for the life of the page: a red box holding whatever string the
service threw — for an offline user, the browser's raw
"TypeError: Failed to fetch" — with no retry and no way to dismiss it.
handleJoin and handleClaim both re-fetch on success, but loadData never
reset the flag, so those loads populated `data` behind an error screen
nobody could see past.
The error is now cleared by a successful load, carries a Try again
button, and once there are challenges on screen it appears as a banner
over them rather than instead of them.
A successful-but-empty response is no longer indistinguishable from a
failure — it says there are no challenges running, rather than leaving
the "Active Challenges" heading above an empty grid.
`data?.challenges.map(...)` stopped its optional chain at `data`, so a
response of `{}` was `undefined.map` and threw during render.
fetchActiveChallenges returns response.json() unchecked, so nothing ruled
that out. readChallengeData normalises the shape instead.
progressPercent replaces the inline `Math.min(x, 100)`, which capped the
top but left the divisor unguarded: a targetValue of 0 produced Infinity
(NaN when progress was 0 too), and `width: "NaN%"` is dropped by the
browser, so the bar silently disappeared rather than looking wrong. A
missing progress value also printed "undefined / 5 reports".
Removed the stray "." that rendered under every completed challenge, and
moved join/claim outcomes off window.alert into the page.
|
@MOHITKOURAV01 is attempting to deploy a commit to the Aditya Mahajan's projects Team on Vercel. A member of the Team first needs to authorize it. |
Thank You for Your Contribution! 🎉Hi @MOHITKOURAV01, Thank you for opening this Pull Request and contributing to our project. We truly appreciate your efforts.
The maintainer @Aditya8369 will review your PR shortly! Happy Contributing! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1105
setError(null)appeared nowhere in this component, so the first failed load ended it for the life of the page: a red box holding whatever string the service threw — for an offline user, the browser's rawTypeError: Failed to fetch— with no button, no link, and no way back other than a reload.Worse, the paths that do re-fetch could not clear it.
handleJoinandhandleClaimbothawait loadData()on success, andloadDatanever reset the flag on the way in, so those loads populateddatabehind an error screen nobody could see past.What changed
data?.challenges.map(...)stopped its optional chain atdata, so a response of{}wasundefined.mapduring render.fetchActiveChallengesreturnsresponse.json()unchecked, so nothing ruled that out.readChallengeDatanormalises the shape.Math.min((progress / target) * 100, 100)capped the top and left the divisor unguarded. AtargetValueof0givesInfinity—NaNwhen progress is0too — andwidth: "NaN%"is dropped by the browser, so the bar silently vanished rather than looking wrong. Negative and missing values did the same, andprogress.progressrendered raw asundefined / 10 reports.✅ Challenge Completed! Claim your reward. .under every completed challenge — on the one line a user is most likely to read closely.window.alert→ the page. Join and claim outcomes are reported in-place instead of blocking the tab.Tests
26 new tests in
src/components/EcoChallengeDashboard.test.jsx.progressPercent,progressCountandreadChallengeDataare asserted directly — including a property-style pass checking thatprogressPercentreturns a finite value in[0, 100]for every hostile input — and the error, empty and malformed-payload paths through the component.Verification