refactor: split large files into focused modules and subcomponents#377
refactor: split large files into focused modules and subcomponents#377
Conversation
Extract ~1,700 lines from lib.rs (3,247 → 1,605 lines) into focused domain modules: - diff_commands.rs (484 lines) — diff computation for local/remote branches - review_commands.rs (143 lines) — code review CRUD operations - timeline.rs (371 lines) — branch timeline construction and commit/review deletion - image_commands.rs (255 lines) — image upload, retrieval, and management - note_commands.rs (90 lines) — note CRUD for branches and projects - github_commands.rs (139 lines) — GitHub/git API wrappers for the frontend - util_commands.rs (212 lines) — open-in-app, preferences, blox auth, etc. What stays in lib.rs: - Managed state (DbState, StoreIncompatibility) - Database migration helpers - Store status commands (get_store_status, confirm_reset_store) - Project commands (CRUD, repo management, delete with cleanup) - Action commands (repo action CRUD) - Frontend-facing timeline types (BranchTimeline, etc.) - get_store helper (now pub(crate)) - Tauri app setup (run function) - Tests for cleanup_project_branches_best_effort All invoke_handler paths updated to use module-qualified names. No functional changes — just reorganization.
Extract ~2,150 lines from BranchCard.svelte (3,161 → 1,000 lines) into focused components and a reactive module: - BranchCardActionsBar.svelte (~860 lines) — running action buttons, primary run action button/pill, more dropdown menu with Actions and Open In submenus, action status event listeners - BranchCardPrButton.svelte (~540 lines) — PR creation/push button, PR status polling, push/PR error/force-push dialogs, option-key tracking for draft PRs - BranchCardSessionManager.svelte.ts (~285 lines) — session creation logic, pending session items, auto review adoption/cancellation, new session modal state BranchCard.svelte remains as the coordinator (~1,000 lines): - Props and local/remote derivation - Timeline loading and review detail fetching - Central session-status-changed event listener (dispatches to child components via refs/callbacks) - Timeline item click/delete handlers and modal state - Drag-and-drop handling - Card layout template and remaining styles No functional changes — pure reorganization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The BranchCardPrButton extraction changed the unpushed commits effect to depend on `hasCodeChanges` (a boolean) instead of `timeline` (the full object). This meant the check wouldn't re-trigger on every timeline refresh, diverging from the original behavior. Pass `timeline` as a prop and use it as the effect dependency, matching the original. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e82899fe92
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (foundUrl) { | ||
| const prNumber = extractPrNumber(foundUrl); | ||
| if (prNumber) { | ||
| commands.updateBranchPr(branch.id, prNumber); |
There was a problem hiding this comment.
Await PR persistence before marking PR created
In handlePrSessionComplete, commands.updateBranchPr(branch.id, prNumber) is no longer awaited, so failures to persist the PR number are silently ignored while prStateStore.setPrCreated still runs. If that write fails (for example due to a transient DB error), the UI reports a created PR but the branch record is left without pr_number, which breaks PR linkage after reload and leaves status refresh paths inconsistent.
Useful? React with 👍 / 👎.
| `PR creation session ${status === 'error' ? 'failed' : 'was cancelled'}.` | ||
| ); | ||
| } | ||
| prStateStore.clearSessionTracking(branch.id); |
There was a problem hiding this comment.
Defer clearing PR session tracking until completion work ends
prStateStore.clearSessionTracking(branch.id) runs immediately after kicking off async message parsing, but this component also has fallback polling (commands.getSession in the $effect above) and the parent completion listener can call handlePrSessionComplete too. A second completion callback that arrives while the first promise is still in flight will see sid as null and take the cancellation error path, producing incorrect error state despite a successful PR session.
Useful? React with 👍 / 👎.
- Narrow mime_type_for_extension to private (only used in image_commands) - Narrow build_branch_timeline to private (only used in timeline) - Revert unintentional rename_all addition on delete_project command - Remove dead onPrSessionComplete/onPushSessionComplete props and call sites from BranchCardPrButton (parent uses bind:this instead) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e82899f to
aff06f2
Compare
- Await `commands.updateBranchPr` in `handlePrSessionComplete` so DB write failures propagate to the error state instead of being silently ignored, preventing PR linkage from breaking after reload. - Add re-entrance guards (`prCompletionInFlight` / `pushCompletionInFlight`) to both completion handlers so a second callback arriving while the first is still in-flight is dropped rather than seeing a null session ID and incorrectly entering the cancellation/error path. - Convert both handlers from fire-and-forget `.then()` chains to async/await with try/finally for clearer control flow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
lib.rsinto 7 focused domain modules:diff_commands,github_commands,image_commands,note_commands,review_commands,timeline, andutil_commandsBranchCard.svelte:BranchCardActionsBar,BranchCardPrButton, andBranchCardSessionManagerTest plan
🤖 Generated with Claude Code