Skip to content

refactor(courses): memoize DiscountProgressBar tier scans and derived…#994

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
chuks68:main
Jul 24, 2026
Merged

refactor(courses): memoize DiscountProgressBar tier scans and derived…#994
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
chuks68:main

Conversation

@chuks68

@chuks68 chuks68 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #987 This PR optimizes rendering performance and aligns the threshold evaluation logic within the DiscountProgressBar component (
DiscountProgressBar.tsx
).

Key Changes
Memoized All Derived Properties:
Wrapped maxThreshold, normalizedSpend, progressPercent, amountToNext, and allUnlocked within useMemo hooks to avoid redundant recalculations on every render.
Consistent Threshold Comparisons:
Updated the tier markers and tier list items to check whether they are unlocked using the memoized normalizedSpend rather than using the raw currentSpend value directly.
Memoized Tier Scans:
Extracted the mapping of DISCOUNT_TIERS and the evaluation of whether a tier is unlocked into a new useMemo block called memoizedTiers. The JSX now loops over this pre-computed list, avoiding scanning and calculation overhead during renders.
Verification Results
Automated Tests
Both unit and integration tests were executed successfully:

Unit Tests: src/components/courses/tests/DiscountProgressBar.test.tsx (5 tests passed)
Integration Tests: src/components/courses/tests/EnrollmentCTA.integration.test.tsx (1 test passed)
bash

✓ src/components/courses/tests/DiscountProgressBar.test.tsx (5 tests) 136ms
✓ src/components/courses/tests/EnrollmentCTA.integration.test.tsx (1 test) 79ms

@drips-wave

drips-wave Bot commented Jul 24, 2026

Copy link
Copy Markdown

@chuks68 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 3b18f67 into rinafcode:main Jul 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memoize DiscountProgressBar tier scans and derived values

2 participants