11import { useCallback , useEffect , useRef , useState } from 'react' ;
22import type { ChangeEvent } from 'react' ;
3+ import type { AddVoiceInput } from '../../store/voiceStore' ;
34import { useVoiceStore } from '../../store/voiceStore' ;
5+ import { useVoiceVerificationStore } from '../../store/voiceVerificationStore' ;
6+ import { useUIStore } from '../../store/uiStore' ;
47import { VoiceCard } from './VoiceCard' ;
58import { VoiceEditDialog } from './VoiceEditDialog' ;
69import { Button } from '../ui/Button' ;
@@ -10,7 +13,7 @@ import {
1013 processVoiceAudioFile ,
1114 isVoiceUploadError ,
1215} from '../../services/voiceUploadService' ;
13- import { toastError , toastSuccess } from '../../hooks/useToast' ;
16+ import { toastError , toastInfo , toastSuccess } from '../../hooks/useToast' ;
1417
1518export function VoiceLibraryPanel ( ) {
1619 const voices = useVoiceStore ( ( s ) => s . voices ) ;
@@ -21,11 +24,12 @@ export function VoiceLibraryPanel() {
2124 const selectedVoiceId = useVoiceStore ( ( s ) => s . selectedVoiceId ) ;
2225 const selectVoice = useVoiceStore ( ( s ) => s . selectVoice ) ;
2326 const deselectVoice = useVoiceStore ( ( s ) => s . deselectVoice ) ;
24- const addVoice = useVoiceStore ( ( s ) => s . addVoice ) ;
2527 const deleteVoice = useVoiceStore ( ( s ) => s . deleteVoice ) ;
2628 const getFilteredVoices = useVoiceStore ( ( s ) => s . getFilteredVoices ) ;
2729 const getAllTags = useVoiceStore ( ( s ) => s . getAllTags ) ;
2830 const loadAudioBlob = useVoiceStore ( ( s ) => s . loadAudioBlob ) ;
31+ const beginVerification = useVoiceVerificationStore ( ( s ) => s . beginVerification ) ;
32+ const setShowVoiceVerificationModal = useUIStore ( ( s ) => s . setShowVoiceVerificationModal ) ;
2933
3034 const [ editingVoiceId , setEditingVoiceId ] = useState < string | null > ( null ) ;
3135 const [ playingVoiceId , setPlayingVoiceId ] = useState < string | null > ( null ) ;
@@ -57,6 +61,15 @@ export function VoiceLibraryPanel() {
5761 fileInputRef . current ?. click ( ) ;
5862 } , [ ] ) ;
5963
64+ const beginVoiceCreationVerification = useCallback (
65+ ( input : AddVoiceInput , audioBlob : Blob ) => {
66+ beginVerification ( input , audioBlob ) ;
67+ setShowVoiceVerificationModal ( true ) ;
68+ toastInfo ( 'Verify voice identity to add this voice to the library' ) ;
69+ } ,
70+ [ beginVerification , setShowVoiceVerificationModal ] ,
71+ ) ;
72+
6073 const handleFileSelect = useCallback (
6174 async ( e : ChangeEvent < HTMLInputElement > ) => {
6275 const file = e . target . files ?. [ 0 ] ;
@@ -73,7 +86,7 @@ export function VoiceLibraryPanel() {
7386 return ;
7487 }
7588
76- addVoice (
89+ beginVoiceCreationVerification (
7790 {
7891 name : result . name ,
7992 durationSeconds : result . durationSeconds ,
@@ -84,7 +97,6 @@ export function VoiceLibraryPanel() {
8497 } ,
8598 result . blob ,
8699 ) ;
87- toastSuccess ( `Voice "${ result . name } " added to library` ) ;
88100 } catch {
89101 toastError ( 'Failed to process voice file' ) ;
90102 } finally {
@@ -94,7 +106,7 @@ export function VoiceLibraryPanel() {
94106 if ( fileInputRef . current ) fileInputRef . current . value = '' ;
95107 }
96108 } ,
97- [ addVoice ] ,
109+ [ beginVoiceCreationVerification ] ,
98110 ) ;
99111
100112 // ─── Preview playback ────────────────────────────────────
@@ -212,7 +224,7 @@ export function VoiceLibraryPanel() {
212224 Voice Library
213225 </ span >
214226 < span className = "text-[9px] text-zinc-600 mr-2" > { voices . length } </ span >
215- < VoiceRecordButton />
227+ < VoiceRecordButton onCapturedVoice = { beginVoiceCreationVerification } />
216228 < Button
217229 variant = "ghost"
218230 size = "sm"
0 commit comments