Skip to content

TT-6827 Add autosave functionality for recording drafts#335

Open
gtryus wants to merge 5 commits into
developfrom
TT-6827-rec-autosave
Open

TT-6827 Add autosave functionality for recording drafts#335
gtryus wants to merge 5 commits into
developfrom
TT-6827-rec-autosave

Conversation

@gtryus
Copy link
Copy Markdown
Contributor

@gtryus gtryus commented May 27, 2026

  • 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 useRecordingAutosave hook and recordingDraftStore (localStorage metadata) to autosave recording drafts.
  • Adds restoreRecordingDraft to 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 thread src/renderer/src/crud/useRecordingAutosave.ts
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,
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this has been addressed.

Comment thread src/renderer/src/crud/useRecordingAutosave.ts Outdated
Comment on lines +44 to +46
if (!passageId) return null;
const draft = getDraft(passageId);
if (!draft) return null;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this doesn't make any sense. The point is to get it from localStorage so of course it should work when isElectron is false.

Greg Trihus 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.
@gtryus gtryus force-pushed the TT-6827-rec-autosave branch from e505a7c to 886e128 Compare May 27, 2026 22:15
@gtryus gtryus requested a review from sarahentzel May 28, 2026 21:06
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.

2 participants