Skip to content

feat: add ChapterContext and per-chapter line counts#28

Merged
dastratakos merged 8 commits into
mainfrom
dastratakos/add-line-numbers
May 4, 2026
Merged

feat: add ChapterContext and per-chapter line counts#28
dastratakos merged 8 commits into
mainfrom
dastratakos/add-line-numbers

Conversation

@dastratakos

@dastratakos dastratakos commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a ChapterContext to centralize shared chapter data and adds per-chapter line change counts (+N/-N) across the UI, mirroring the hosted Stage monorepo.

Changes

  • Extract a reusable LineCounts component from the repeated green/red +N/-N pattern in file-picker and file-header
  • Add ChapterContext with ChapterProvider (in PullRequestLayout) exposing runId, sorted chapters, and a chapterLineCountsMap
  • Display per-chapter line counts in the chapter navigator dropdown, chapter side panel header, and chapters index page
  • Refactor ChapterNavigator, ChapterSidePanel, and ChapterDetailContent to read shared data from context instead of props, reducing prop drilling

Testing

  • pnpm typecheck passes
  • pnpm lint passes
  • One pre-existing test failure in server.test.ts (unrelated to these changes)

Open in Stage

DRY up the repeated green/red +N/-N line count pattern used in
file-picker and file-header into a reusable LineCounts component.
Introduce ChapterContext that centralizes chapter data and per-chapter
line counts (linesAdded/linesDeleted). The provider lives in
PullRequestLayout, making chapter data available to both the index
and detail pages without prop drilling.
ChapterNavigator now reads runId, chapters, and line counts from
ChapterContext instead of receiving them as props. Each chapter in the
dropdown shows its +N/-N line change counts. Removes runId and
allChapters props from ChapterSidePanel.
Display +N/-N line change counts below the chapter title in the side
panel, sourced from ChapterContext.
Each chapter entry in the index now shows +N/-N line change counts
floated to the right of the chapter title, sourced from ChapterContext.
ChapterDetailContent now reads runId and allChapters from
ChapterContext instead of receiving them as props, reducing its
interface from 5 props to 3.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a ChapterProvider and useChapterContext to centralize chapter data and calculate line counts (additions and deletions) per chapter. A new shared LineCounts component was added and integrated into the chapter navigator, side panel, file picker, and index page to provide visual feedback on the scale of changes. Feedback indicates that the current calculation for chapter line counts incorrectly uses total file additions/deletions instead of summing specific hunks, leading to inflated numbers when files span multiple chapters. Furthermore, the patch parsing logic within the context provider should be optimized to avoid redundant processing for each chapter.

Comment thread packages/web/src/lib/chapter-context.tsx
Comment thread packages/web/src/lib/chapter-context.tsx

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1282050. Configure here.

Comment thread packages/web/src/components/chapter/chapter-side-panel.tsx
Comment thread packages/web/src/routes/chapter-detail-page.tsx
Comment thread packages/web/src/lib/chapter-context.tsx
When a chapter has zero additions and deletions, LineCounts returns
null but the fallback spacer was unreachable because the counts object
is always truthy. Check for non-zero counts before rendering.
ChapterDetailPage now reads the sorted chapters array from
ChapterContext instead of maintaining its own duplicate sort,
eliminating the fragile coupling between two independent sorts.
@dastratakos dastratakos marked this pull request as ready for review May 4, 2026 19:13
@dastratakos dastratakos merged commit 91ec9f6 into main May 4, 2026
5 checks passed
@dastratakos dastratakos deleted the dastratakos/add-line-numbers branch May 4, 2026 19:13
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