TT-6827 Add autosave functionality for recording drafts#335
Open
gtryus wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds local autosave + restore support for recording drafts in the renderer, so in-progress audio can be recovered after navigation/reload and users get feedback that a draft has been saved locally.
Changes:
- Introduces a
useRecordingAutosavehook andrecordingDraftStore(localStorage metadata) to autosave recording drafts. - Adds
restoreRecordingDraftto load the latest local draft when it’s newer than the server media. - Wires autosave/restore into
MediaRecord, and adds localization + tests for the new behavior.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/renderer/src/store/localization/reducers.tsx | Adds passageRecord.autosavedLocally English string. |
| src/renderer/src/store/localization/model.tsx | Extends passage record strings type with autosavedLocally. |
| src/renderer/src/store/localization/exported-strings-name.json | Updates exported strings bundle name. |
| src/renderer/src/crud/useRecordingAutosave.ts | New autosave hook writing drafts locally and tracking metadata. |
| src/renderer/src/crud/useRecordingAutosave.test.ts | Tests for autosave debounce, guard conditions, and draft clearing. |
| src/renderer/src/crud/restoreRecordingDraft.ts | Restores a draft blob when it should supersede server media. |
| src/renderer/src/crud/restoreRecordingDraft.test.ts | Tests restore behavior based on timestamps. |
| src/renderer/src/crud/recordingDraftStore.ts | localStorage-backed draft metadata store + restore decision logic. |
| src/renderer/src/crud/recordingDraftStore.test.ts | Tests draft CRUD and restore decision logic. |
| src/renderer/src/crud/index.ts | Re-exports new autosave/restore modules. |
| src/renderer/src/components/MediaRecord.tsx | Integrates autosave + draft restore into recording UI lifecycle. |
| localization/TranscriberAdmin-en.xlf | Adds new localization unit for autosave message. |
| localization/TranscriberAdmin-en-1.2.xliff | Adds new localization unit for autosave message (with sourcefile context). |
Comment on lines
+54
to
+71
| const saveDraft = useCallback(async () => { | ||
| if (!passageId || !audioBlob || !filetype) return; | ||
| try { | ||
| const blobType = audioBlob.type || mimeType; | ||
| const file = new File( | ||
| [audioBlob], | ||
| `${defaultFilename}.${filetype}`, | ||
| { type: blobType } | ||
| ); | ||
| const written = await writeFileLocal(file); | ||
| upsertDraft({ | ||
| passageId, | ||
| mediafileId: mediaId, | ||
| relativeMediaPath: written.relativeMediaPath, | ||
| performedBy, | ||
| mimeType: blobType, | ||
| filetype, | ||
| }); |
Contributor
Author
There was a problem hiding this comment.
this has been addressed.
Comment on lines
+44
to
+46
| if (!passageId) return null; | ||
| const draft = getDraft(passageId); | ||
| if (!draft) return null; |
Contributor
Author
There was a problem hiding this comment.
this doesn't make any sense. The point is to get it from localStorage so of course it should work when isElectron is false.
added 4 commits
May 27, 2026 17:12
- Introduced `useRecordingAutosave` hook to manage automatic saving of recording drafts. - Implemented `recordingDraftStore` for storing and retrieving drafts in local storage. - Added `restoreRecordingDraft` function to restore drafts based on their timestamps. - Updated `MediaRecord` component to utilize the new autosave and restore features. - Added localization for the "Saved locally" message. - Created tests for the new functionality to ensure reliability.
- Introduced load generation reference to manage in-flight load/restore operations. - Updated `tryRestoreFromDraft` and `handleLoadAudio` functions to accept generation parameters for better control over state changes. - Modified draft restoration logic to prevent conflicts when mediaId or passageId changes. - Adjusted `shouldRestoreDraft` function to return false for invalid draft timestamps, improving draft restoration reliability.
- Reorganized the mock for `useFetchMediaUrl` to enhance clarity and maintainability. - Introduced a separate function for the mock implementation, allowing for better structure. - Updated the mock to include additional exports and maintain consistency with the actual module. - Enhanced the key mapping logic in the global context mock for improved test accuracy.
…onality - Added `recordingDraftFiles` module to handle draft file operations, including resolving paths and deleting files. - Introduced tests for draft file management to ensure correct functionality. - Updated `useRecordingAutosave` to delete previous draft files before saving new ones, improving autosave reliability. - Refactored `clearDraft` to utilize `purgeRecordingDraft`, ensuring proper cleanup of drafts.
e505a7c to
886e128
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
useRecordingAutosavehook to manage automatic saving of recording drafts.recordingDraftStorefor storing and retrieving drafts in local storage.restoreRecordingDraftfunction to restore drafts based on their timestamps.MediaRecordcomponent to utilize the new autosave and restore features.