From ef3c3a7f8ce9f42428d1275714030d6fae6caec0 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Thu, 29 Jan 2026 18:56:22 -0800 Subject: [PATCH] Refactor ProfileForm for improved readability and maintainability - Reorganized import statements for clarity. - Enhanced conditional checks for restoring saved files with improved formatting. - Streamlined draft saving logic by consolidating variable declarations. - Updated UI components for better structure and readability in the form layout. --- .../components/VoiceProfiles/ProfileForm.tsx | 456 +++++++++--------- 1 file changed, 233 insertions(+), 223 deletions(-) diff --git a/app/src/components/VoiceProfiles/ProfileForm.tsx b/app/src/components/VoiceProfiles/ProfileForm.tsx index 3677c378..c45dc9f1 100644 --- a/app/src/components/VoiceProfiles/ProfileForm.tsx +++ b/app/src/components/VoiceProfiles/ProfileForm.tsx @@ -43,7 +43,7 @@ import { useSystemAudioCapture } from '@/lib/hooks/useSystemAudioCapture'; import { useTranscription } from '@/lib/hooks/useTranscription'; import { isTauri } from '@/lib/tauri'; import { formatAudioDuration, getAudioDuration } from '@/lib/utils/audio'; -import { useUIStore, type ProfileFormDraft } from '@/stores/uiStore'; +import { type ProfileFormDraft, useUIStore } from '@/stores/uiStore'; import { AudioSampleRecording } from './AudioSampleRecording'; import { AudioSampleSystem } from './AudioSampleSystem'; import { AudioSampleUpload } from './AudioSampleUpload'; @@ -265,11 +265,15 @@ export function ProfileForm() { }); setSampleMode(profileFormDraft.sampleMode); // Restore the file if we have it saved - if (profileFormDraft.sampleFileData && profileFormDraft.sampleFileName && profileFormDraft.sampleFileType) { + if ( + profileFormDraft.sampleFileData && + profileFormDraft.sampleFileName && + profileFormDraft.sampleFileType + ) { const file = base64ToFile( profileFormDraft.sampleFileData, profileFormDraft.sampleFileName, - profileFormDraft.sampleFileType + profileFormDraft.sampleFileType, ); form.setValue('sampleFile', file); } @@ -446,8 +450,9 @@ export function ProfileForm() { if (!newOpen && isCreating) { // Save draft when closing the create modal const values = form.getValues(); - const hasContent = values.name || values.description || values.referenceText || values.sampleFile; - + const hasContent = + values.name || values.description || values.referenceText || values.sampleFile; + if (hasContent) { const draft: ProfileFormDraft = { name: values.name || '', @@ -456,7 +461,7 @@ export function ProfileForm() { referenceText: values.referenceText || '', sampleMode, }; - + // Save file as base64 if present if (values.sampleFile) { try { @@ -467,11 +472,11 @@ export function ProfileForm() { // If file conversion fails, just don't save the file } } - + setProfileFormDraft(draft); } } - + setOpen(newOpen); if (!newOpen) { setEditingProfileId(null); @@ -491,135 +496,116 @@ export function ProfileForm() {
- {editingProfileId ? 'Edit Voice' : 'Clone voice'} - - {editingProfileId - ? 'Update your voice profile details and manage samples.' - : 'Create a new voice profile with an audio sample to clone the voice.'} - - {isCreating && profileFormDraft && ( -
- Draft restored - -
- )} -
+ + {editingProfileId ? 'Edit Voice' : 'Clone voice'} + + + {editingProfileId + ? 'Update your voice profile details and manage samples.' + : 'Create a new voice profile with an audio sample to clone the voice.'} + + {isCreating && profileFormDraft && ( +
+ Draft restored + +
+ )} + -
- -
- {/* Left column: Sample management */} -
- {isCreating ? ( - <> - { - const newMode = v as 'upload' | 'record' | 'system'; - // Cancel any active recordings when switching modes - if (isRecording && newMode !== 'record') { - cancelRecording(); - } - if (isSystemRecording && newMode !== 'system') { - cancelSystemRecording(); - } - setSampleMode(newMode); - }} - > - + +
+ {/* Left column: Sample management */} +
+ {isCreating ? ( + <> + { + const newMode = v as 'upload' | 'record' | 'system'; + // Cancel any active recordings when switching modes + if (isRecording && newMode !== 'record') { + cancelRecording(); + } + if (isSystemRecording && newMode !== 'system') { + cancelSystemRecording(); + } + setSampleMode(newMode); + }} > - - - Upload - - - - Record - - {isTauri() && isSystemAudioSupported && ( - - - System Audio + + + + Upload - )} - - - - ( - MAX_AUDIO_DURATION_SECONDS - } - fieldName={name} - /> + + + Record + + {isTauri() && isSystemAudioSupported && ( + + + System Audio + )} - /> - + - - ( - - )} - /> - + + ( + MAX_AUDIO_DURATION_SECONDS + } + fieldName={name} + /> + )} + /> + - {isTauri() && isSystemAudioSupported && ( - + ( - - )} - - ( - - Reference Text - -