Optimistic UI updates for XP and improved comment section sorting
Introduces optimistic UI updates for XP/level on lesson/challenge completion and refactors the comment section to handle sorting and error states without relying on Firestore orderBy. Also adds real-time profile updates and manual profile mutations for user state.
- Implements optimistic XP/level/badge updates in
ChallengePageandLessonPageusing the newupdateProfilefunction fromuseAuth. - Refactors
lib/auth.jsto provide real-time profile updates viaonSnapshotand anupdateProfilemethod for local state mutation. - Updates
/app/api/challenges/submit/route.jsto relax challengeId submission logic and mark the route as "force-dynamic". - Refactors
CommentSection.jsto remove FirestoreorderByin queries, instead performing client-side sorting (by upvotes and creation time for root comments, by creation time for replies). - Adds error handling for comment and reply posting, displaying alerts on failure and preventing state inconsistencies.
- Refactors code for better formatting and minor UI/UX improvements (button styling, event handling).
- Users see immediate XP, level, and badge updates on UI after completing lessons or challenges, improving responsiveness.
- User profile information stays in sync with Firestore changes in real time.
- Comment and reply ordering remains correct even without Firestore indexes, improving robustness and reliability.
- Graceful error handling prevents silent failures in comment and reply posting.
- No breaking API changes, but relies on new optimistic state management and real-time profile subscription.
- Potential for minor increased memory usage due to additional listeners, but no major performance impact expected.