-
-
Notifications
You must be signed in to change notification settings - Fork 531
Fix: Questions button not showing due to incorrect data structure access #2588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: production
Are you sure you want to change the base?
Conversation
…nData Refactor question counting to use a new QuestionData type that includes 'total' and 'types' fields, ensuring accurate visibility of questions button and related UI elements. This fixes issues where the button wasn't showing due to outdated count checks.
WalkthroughThe PR refactors the question counting system to replace simple numeric counts with a structured Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (12)**/*.*📄 CodeRabbit inference engine (.cursor/rules/bug-handling-with-todo-comments.mdc)
Files:
**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/next-js-conventions.mdc)
Files:
src/components/**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/react-functional-components.mdc)
Files:
**/*.{tsx,jsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.{ts,tsx,d.ts}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
{src,types}/**/*.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.tsx📄 CodeRabbit inference engine (CLAUDE.md)
Files:
{src,types}/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/components/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/utils/auth/api.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (2)📚 Learning: 2025-10-26T10:22:52.381ZApplied to files:
📚 Learning: 2025-10-19T11:34:07.609ZApplied to files:
🧬 Code graph analysis (2)src/components/QuranReader/ReadingView/context/PageQuestionsContext.tsx (1)
src/hooks/auth/useCountRangeQuestions.ts (2)
🔇 Additional comments (9)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where the "Explore Answers" button was not appearing for verses with questions. The root cause was that the code was comparing the entire QuestionData object (containing types and total properties) to a number, which always evaluated to false.
Key Changes:
- Updated data access patterns to correctly access the
.totalproperty ofQuestionDataobjects with optional chaining - Added
QuestionDatatype definition and updated all related type signatures throughout the codebase - Fixed button visibility logic in both Reading View and Translation View
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| api.ts | Added QuestionData type export and updated return type for countQuestionsWithinRange function |
| useCountRangeQuestions.ts | Updated all type signatures to use Record<string, QuestionData> instead of Record<string, number> |
| PageQuestionsContext.tsx | Updated context type to use QuestionData for type safety |
| TranslationPageVerse.tsx | Fixed questions check to access .total property with optional chaining |
| QuestionsButton/index.tsx | Fixed questions check to access .total property with optional chaining |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
Closes: QF-3857
The "Explore Answers" button was not appearing for verses with questions in both Translation View and Reading View.
Root Cause
The API returns questions data with this structure:
{ "1:2": { "types": { "TAFSIR": 3, "COMMUNITY": 2 }, "total": 5 } }However, the code was comparing the entire object to a number:
This comparison always evaluated to
false, preventing the button from showing.Solution
Updated all code to correctly access the
.totalproperty:Changes
1. Fixed Data Access (3 files)
.totalproperty access with optional chaining.totalproperty access with optional chaining2. Updated Type Definitions (3 files)
QuestionDatatype export matching API response structureRecord<string, number>toRecord<string, QuestionData>QuestionDataThis ensures type safety and prevents similar bugs in the future.
Testing
Verified with production API data:
Files Changed
Impact
Checklist
Summary by CodeRabbit
Bug Fixes
Refactor