File tree Expand file tree Collapse file tree 1 file changed +14
-14
lines changed
package/src/components/MessageInput/hooks Expand file tree Collapse file tree 1 file changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -15,23 +15,23 @@ export const useAudioPreviewManager = (files: LocalAttachment[]) => {
1515 > ( { } ) ;
1616
1717 useEffect ( ( ) => {
18- const updatedStateMap = Object . fromEntries (
19- files . map ( ( attachment ) => {
20- const id = attachment . localMetadata . id ;
21- const existingConfig = audioAttachmentsStateMap [ id ] ;
18+ setAudioAttachmentsStateMap ( ( prevState ) => {
19+ const updatedStateMap = Object . fromEntries (
20+ files . map ( ( attachment ) => {
21+ const id = attachment . localMetadata . id ;
2222
23- const config : AudioConfig = {
24- duration : attachment . duration ?? existingConfig ?. duration ?? 0 ,
25- paused : existingConfig ?. paused ?? true ,
26- progress : existingConfig ?. progress ?? 0 ,
27- } ;
23+ const config : AudioConfig = {
24+ duration : attachment . duration ?? prevState [ id ] ?. duration ?? 0 ,
25+ paused : prevState [ id ] ?. paused ?? true ,
26+ progress : prevState [ id ] ?. progress ?? 0 ,
27+ } ;
2828
29- return [ id , config ] ;
30- } ) ,
31- ) ;
29+ return [ id , config ] ;
30+ } ) ,
31+ ) ;
3232
33- setAudioAttachmentsStateMap ( updatedStateMap ) ;
34- // eslint-disable-next-line react-hooks/exhaustive-deps
33+ return updatedStateMap ;
34+ } ) ;
3535 } , [ files ] ) ;
3636
3737 // Handler triggered when an audio is loaded in the message input. The initial state is defined for the audio here
You can’t perform that action at this time.
0 commit comments