Repository navigation
Conversation
…aRecord's setHasTake effect MediaRecord's setHasTake effect only copied a derived value up to the parent (a CODING_STANDARDS "Effects" finding). Drop the prop and effect; ResourceRecordPanel now marks hadTake from afterUploadCb on a successful upload and clears it when a new recording starts or the Record tab is re-entered, so Next still carries an already-uploaded take forward after Back. Adds ResourceRecordPanel tests for the Back cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
The change still contains an active test issue where controlsRef is forcibly cast with as never, bypassing the intended RefObject<MediaUploadControlsRef> typing contract and conflicting with the project's typing standards, so the test setup should be corrected to provide a properly shaped controlsRef.current instead.
1 open issue
What changed in this PR
Refactors the add-resource wizard recording flow so ResourceRecordPanel owns the “uploaded take exists” state (hadTake) instead of relying on MediaRecord to push derived state upward via an effect.
Changes:
- Removed
setHasTakeand its derived-state syncing effect fromMediaRecord. - Added
hadTakestate toResourceRecordPanel, set on successful upload and cleared when a new recording starts or when re-entering the record step. - Added Jest coverage to verify wizard Back/Next behavior after upload, handling of failed uploads, and non-wizard Save gating.
| File | Description |
|---|---|
| web/src/components/PassageDetail/Internalization/ResourceRecordPanel.tsx | Moves “uploaded take exists” tracking into the panel (hadTake) and updates button enablement logic to preserve wizard Next behavior after an upload while keeping non-wizard Save gated on unsaved changes. |
| web/src/components/PassageDetail/Internalization/ResourceRecordPanel.test.tsx | Adds tests covering Next/Save enablement across upload success/failure, Back navigation, and starting a new recording resetting the uploaded-take state. |
| web/src/components/MediaRecord.tsx | Removes the setHasTake prop and the effect that copied derived hasTake state upward, leaving the remaining setCanSave effect TODO for later cleanup. |
Review effort: Balanced
…nel reads it Replaces the hadTake bookkeeping, which missed a deleted take. MediaRecord is split into useMediaRecord (state + save logic, computing needsSave and hasTake during render), MediaRecordView (markup) and a MediaRecord wrapper for existing hosts, following the AudioDownload / useAudioDownload pattern. The add-resource Record tab owns the hook, so its button reads needsSave and hasTake directly: no effect copies them up and no events are tracked. setCanSave is now optional and only fires for hosts that pass it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
Outstanding review findings note missing required justifications for exhaustive-deps suppressions and a maintainability concern with a 748-line hook module that exceeds project size guidelines.
3 open issues
1 resolved since last review
Review effort: Balanced
| controlsRef.current.handleAddOrSave = () => startSave(myToolId); | ||
| controlsRef.current.handleAddOrSave = () => startSave(RECORD_TOOL_ID); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps |
| /** The recorder's state and save logic; render it with MediaRecordView. */ | ||
| export function useMediaRecord(props: IMediaRecordStateProps) { | ||
| const { | ||
| toolId, |
| useEffect(() => { | ||
| if (mediaId !== mediaState.id) fetchMediaUrl({ id: mediaId ?? '' }); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [mediaId]); |

Stacked on #875 (
resource-upload-context); retarget todeveloponce #875 merges.Resolves the
TODO cleanup in next PRon MediaRecord'ssetHasTakeeffect, which only copied a derived value up to the parent (a CODING_STANDARDS "Effects" finding).Approach
The first commit replaced the effect with
hadTakebookkeeping in the panel (set on upload, cleared on new recording). Review showed that was fragile: it missed a deleted take, and any other way a take leaves the waveform would be the same bug. The second commit replaces it by lifting the recorder state up instead:MediaRecordis split, following the existingAudioDownload/useAudioDownload/AudioDownloadViewpattern:useMediaRecord(new fileuseMediaRecord.ts): all of MediaRecord's state and save logic, moved unchanged. It computesneedsSaveandhasTakeduring render and returns them.MediaRecordView: the markup, rendered from the hook's return value.MediaRecord: a two-line wrapper (hook + view), so every other host is unchanged.ResourceRecordTab, mounted only while that tab shows, so it still starts fresh on each switch) callsuseMediaRecorditself and rendersMediaRecordView. Its button readsonNext ? rec.hasTake : rec.needsSavedirectly: no effect, no copied state, no event tracking. Deleting a take, editing it, etc. are all covered becausehasTakeis derived from the waveform state.setHasTakeis gone.setCanSaveis now optional and its effect only runs for hosts that pass it; the TODO there says to move those hosts to the hook + view pattern and drop the effect.Test plan
npm run typecheckclean; prettier and eslint clean on changed files.ResourceRecordPanel.test.tsxcovers the button rule (wizard Next onhasTake, plain Save onneedsSave).MediaRecord.recording.cy.tsx/MediaRecord.deleteRegion.cy.tsx(not run locally).🤖 Generated with Claude Code