Skip to content

feat: pomodoro counter + long break logic (Day 4)#27

Merged
MinitJain merged 11 commits intomainfrom
feat/pomodoro-counter
Apr 17, 2026
Merged

feat: pomodoro counter + long break logic (Day 4)#27
MinitJain merged 11 commits intomainfrom
feat/pomodoro-counter

Conversation

@MinitJain
Copy link
Copy Markdown
Owner

@MinitJain MinitJain commented Apr 17, 2026

Summary

  • Cycle persists on refreshfocusCount now inits from session.pomos_done (DB-backed) instead of always starting at 0
  • pomos_done written to DB on every focus completion (auto-break and manual skip paths) and reset to 0 on settings change
  • #N today badge — fetches today's count from pomodoro_logs on mount; increments optimistically on each completion (auth users only)
  • Simplified round label — always shows "N pomodoros completed", consistent across all modes (focus / short / long break)
  • Long break logic untouched — still triggers after settings.rounds completions

Test plan

  • Complete a focus session — pomos_done increments in DB, label updates, #N today increments
  • Refresh page mid-session — cycle count preserved from DB
  • Complete 4 focus rounds — long break triggers correctly
  • Change settings — pomos_done resets to 0 in DB and UI
  • Guest user — #N today badge hidden, rest works normally

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Session tracking now displays a counter showing pomodoros completed today.
  • Tests

    • Added comprehensive test suites for timer functionality and session management.
  • Chores

    • Added testing framework and dependencies; updated security policies.

MinitJain and others added 4 commits April 16, 2026 21:09
react-easy-crop uses blob: URLs to render the selected image. The existing
img-src CSP blocked blob: causing a blank crop preview. Also ensure the
react-easy-crop CSS import is present for correct image positioning.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Install vitest, @testing-library/react, @testing-library/jest-dom, jsdom
- 42 tests across 3 suites:
  - lib/timer: computeTimeLeft, isTimerExpired, formatTime, createTimerState,
    sessionToTimerState, computeProgress (29 tests)
  - hooks/useTimer: start, pause, reset, setMode, skipAndStart, onExpire,
    timeLeft floor, applyState (9 tests)
  - lib/writeQueue: serialization order, error recovery, last-write wins (4 tests)
- Add `npm test` step to CI workflow (runs before typecheck + build)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Init focusCount from session.pomos_done so cycle persists on refresh
- Persist pomos_done to DB on every focus completion (both auto-break
  and manual skip paths) and reset to 0 on settings change
- Fetch today's pomodoro count from pomodoro_logs on mount; show as
  "#N today" badge for authenticated users (optimistic +1 on completion)
- Simplify round label to "N pomodoros completed" — consistent across
  all timer modes (focus / short break / long break)
- Long break logic unchanged: triggers after settings.rounds completions

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pomodoro-jam Ready Ready Preview, Comment Apr 17, 2026 11:17am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Warning

Rate limit exceeded

@MinitJain has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 36 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 28 minutes and 36 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2c8e717c-720f-4c4b-9a85-68013a30a22c

📥 Commits

Reviewing files that changed from the base of the PR and between 65b397a and 9518d46.

📒 Files selected for processing (2)
  • components/session/SessionProvider.tsx
  • components/session/StatsTab.tsx

Walkthrough

This PR establishes a comprehensive testing infrastructure using Vitest, adds test suites for the useTimer hook and timer utilities, implements pomodoro session counting with daily completion tracking persisted to Supabase, updates CSP headers to allow blob image sources, and adds a test step to the CI workflow.

Changes

Cohort / File(s) Summary
Test Infrastructure
vitest.config.ts, vitest.setup.ts, package.json
Added Vitest configuration with React plugin, jsdom environment, global test APIs, and @testing-library/jest-dom setup. Updated package.json with test scripts (npm test, npm run test:watch) and testing dependencies.
useTimer Hook Tests
__tests__/hooks/useTimer.test.tsx
Added 184-line test suite verifying hook state transitions (start, pause, reset, setMode, skipAndStart), expiration behavior, time computation, and external state application with fake timers.
Timer Utilities Tests
__tests__/lib/timer.test.ts, __tests__/lib/writeQueue.test.ts
Added 195-line test suite for timer utilities (computeTimeLeft, isTimerExpired, formatTime, createTimerState, sessionToTimerState, computeProgress) and 56-line test for write queue serialization behavior.
Session State Management
components/session/SessionProvider.tsx
Added pomodoro completion tracking: initialized focusCountRef and todayCount state from session data, added Supabase query to fetch today's completed pomodoros, incremented todayCount and persisted pomos_done on focus completion and skip, updated UI label from round-based to completion-based formatting.
Configuration & Build
.github/workflows/ci.yml, next.config.js
Added Test job step to CI workflow after Lint and before Typecheck. Updated CSP header img-src directive from data: to blob:.
Import Ordering
components/profile/AvatarCropModal.tsx
Reordered imports to place type-only Area import after CSS import.

Sequence Diagram

sequenceDiagram
    participant SessionProvider
    participant Supabase Query
    participant Supabase DB
    participant UI

    SessionProvider->>SessionProvider: Initialize focusCountRef from session.pomos_done
    SessionProvider->>Supabase Query: Fetch completed pomodoros since today start
    Supabase Query->>Supabase DB: Query pomodoro_logs with completed_at >= start-of-today
    Supabase DB-->>Supabase Query: Return count
    Supabase Query-->>SessionProvider: Set todayCount state
    SessionProvider->>UI: Render "#<todayCount> today" badge

    rect rgba(100, 150, 200, 0.5)
    Note over SessionProvider,Supabase DB: On focus completion or skip
    SessionProvider->>SessionProvider: Increment todayCount
    SessionProvider->>Supabase DB: Update sessions.pomos_done
    Supabase DB-->>SessionProvider: Confirmation
    SessionProvider->>UI: Update completion count label
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: pomodoro counter + long break logic (Day 4)' accurately reflects the main feature additions: pomodoro counter persistence via DB-backed initialization and simplified round labeling, with testing infrastructure also added.
Description check ✅ Passed The PR description comprehensively covers the changes (DB persistence, today badge, simplified labels), provides a detailed test plan with specific scenarios, and includes all critical checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pomodoro-counter

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Use enqueueSessionUpdate (serialized write queue from main) instead of
direct supabase calls in handleExpire and handleSkip, while keeping
pomos_done persistence from this branch.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Changing durations/rounds is unrelated to completed pomodoro count.
Removed pomos_done: 0 from handleApplySettings DB update and the
in-memory focusCount reset.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add three-tab layout to session screen:
- Timer tab: existing timer UI (unchanged)
- Tasks tab: placeholder for Day 7
- Stats tab: full stats dashboard with today's pomodoro count,
  focus minutes, sessions, duration; weekly bar chart; lifetime
  mastery grid (total pomodoros, focus hours, streaks); activity
  heatmap; profile card with avatar, name, bio

Stats data fetched client-side from pomodoro_logs + profiles.
Guests see a sign-in prompt on the Stats tab.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@MinitJain MinitJain merged commit ded78b0 into main Apr 17, 2026
4 checks passed
@MinitJain MinitJain deleted the feat/pomodoro-counter branch April 17, 2026 11:28
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.

1 participant