Repository navigation
Refactor Gamification Load Logic to Pure Function - #296
albertoivo merged 1 commit into
Conversation
Extracted the complex inline data processing logic from `loadGamification` inside `src/hooks/gamification/useGamificationStore.ts` into a pure, testable function `processLoadedGamificationData` in `src/utils/gamification/loadLogic.ts`. This adheres to the Single Responsibility Principle, making the `useGamificationStore` hook smaller and focused solely on React lifecycles and state/Firestore integration, while delegating the logic for daily resets, legacy migrations, streak updates, and pet status checks to the new pure utility. - Created `src/utils/gamification/loadLogic.ts`. - Updated `src/hooks/gamification/useGamificationStore.ts` to consume the new function. - Updated `src/utils/gamificationState.ts` to export the new module. - Resolved tests failures by handling edge cases (like `isInitial`) in the new logic and streak logic updates. Co-authored-by: albertoivo <1276520+albertoivo@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Visit the preview URL for this PR (updated for commit 37d4231): https://pyexplorer-cd32d--pr296-refactor-extract-gam-a2br6nn5.web.app (expires Mon, 19 Oct 2026 13:16:58 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 916b4905e0cdc420f3368c8eb19b2f2e90c3be61 |
This PR extracts the heavy inline business logic for processing loaded gamification data out of the
useGamificationStorehook and into a pure utility function.Changes
src/utils/gamification/loadLogic.ts: ContainsprocessLoadedGamificationDatawhich handles:src/hooks/gamification/useGamificationStore.ts: Replaced the large inlineif/elselogic block within theloadGamificationcallback with a clean call toprocessLoadedGamificationData.src/utils/gamification/streakLogic.ts: AdjustedmigrateLegacyStreakslightly to handle missing fields correctly when spreading to new values.src/utils/gamificationState.ts: Exported the new logic.Benefits
processLoadedGamificationDatais a pure function that can be easily unit-tested.useGamificationStorehook.PR created automatically by Jules for task 14052783801156281986 started by @albertoivo