Skip to content

refactor(editor): move the Replace-audio modal to src/replace-audio.js (R2, step 32) - #184

Merged
byrongamatos merged 1 commit into
mainfrom
refactor/r2-step32-replace-audio
Jul 10, 2026
Merged

refactor(editor): move the Replace-audio modal to src/replace-audio.js (R2, step 32)#184
byrongamatos merged 1 commit into
mainfrom
refactor/r2-step32-replace-audio

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

What

Step 32 of the R2 module-extraction refactor: move the Replace-audio modal out of src/main.js into a new native ES module src/replace-audio.js.

Swap the session's audio track from a local file or a YouTube URL, decode it, and re-sync playback state (buffer, cursor, scroll bounds, play/sync buttons).

How the seam is drawn

Clean self-contained leaf:

  • 4 window.editor* handlers (editorShowReplaceAudioModal / editorHideReplaceAudioModal / editorSetReplaceAudioMode / editorApplyReplaceAudio) become named exports, re-attached by main.js.
  • 0 back-exports; no new host hooks (draw/updateTimeDisplay already exist, reached through host).
  • Module imports resolve to existing modules: audio.js (loadAudio/stopPlayback), create.js (_uploadAudioForMode/createState), loop.js (_editorApplyScrollBounds), state, ui.
  • Removed 2 now-dead main.js imports (_uploadAudioForMode, createState) that served only the moved code.

main.js drops ~111 lines. 33 modules.

Verification

  • 90/90 JS suites pass; ESLint gate clean (0 errors); strict no-undef clean on replace-audio.js.
  • Codex preflight: 0 correctness issues.
  • New headless harness (verify_replace_audio.py): 4 handlers bound, modal opens (gated on S.sessionId) and closes, file/YouTube mode toggle (input visibility + active button), and both apply-with-no-input pre-check messages ("Choose a file" / "Enter a YouTube URL" — proving editorApplyReplaceAudio routes into the module and its create.js import resolves), zero page errors. Negative-checked by dropping a re-attach.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Replace the current session audio using either a local audio file or a YouTube URL.
    • Audio replacement now refreshes playback and editor controls automatically after processing.
  • Bug Fixes
    • Improved handling of unsupported audio formats with clear error messages.
    • Prevented playback and synchronization issues when replacing audio during an active session.
    • Added clearer status updates for successful replacements and required follow-up actions.

…s (R2, step 32)

Extract the replace-audio flow (swap the session's audio track from a file or a
YouTube URL, decode, and re-sync playback) out of the src/main.js monolith into
a new native ES module. Clean self-contained leaf: 4 window.editor* handlers
re-attached by main.js, 0 back-exports, no new host hooks (draw/updateTimeDisplay
already exist). Removed 2 now-dead main.js imports (_uploadAudioForMode,
createState) that served only the moved code.

main.js drops ~111 lines. 33 modules.

Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef
clean on replace-audio.js, Codex preflight 0 issues. New headless harness drives
the modal: 4 handlers bound, open/close, file/YouTube mode toggle (input
visibility + active button), and both apply-with-no-input pre-check messages
(editorApplyReplaceAudio routing into the module), zero page errors.
Negative-checked by dropping a re-attach.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cde20d9c-f498-4d87-a878-5aac4628d012

📥 Commits

Reviewing files that changed from the base of the PR and between 64548ce and 874c684.

📒 Files selected for processing (2)
  • src/main.js
  • src/replace-audio.js

📝 Walkthrough

Walkthrough

The replace-audio modal flow moves from src/main.js into src/replace-audio.js. The editor retains its global handler bindings, while modal state, input validation, upload/API handling, audio reloading, and status updates are implemented in the dedicated module.

Changes

Replace-audio flow

Layer / File(s) Summary
Modal flow and audio replacement
src/replace-audio.js
Adds modal state and mode switching, validates and uploads local or YouTube audio, calls the replacement API, reloads the audio buffer, updates editor state, and reports success or errors.
Editor integration wiring
src/main.js
Removes the inline replace-audio implementation and related imports, then exposes the imported handlers through the existing window globals.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main refactor: moving the Replace-audio modal into src/replace-audio.js.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/r2-step32-replace-audio

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

@byrongamatos
byrongamatos merged commit c69c425 into main Jul 10, 2026
4 checks passed
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