Skip to content

Commit 569ed39

Browse files
authored
fix: regression in file upload preview remove item (#2919)
* fix: regression in file upload preview remove item * fix: regression in file upload preview remove item
1 parent 3627f32 commit 569ed39

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

package/src/components/MessageInput/FileUploadPreview.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { FlatList, I18nManager, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
33

44
import { UploadProgressIndicator } from './UploadProgressIndicator';
@@ -166,19 +166,19 @@ const FileUploadPreviewWithContext = <
166166
// Handler triggered when an audio is loaded in the message input. The initial state is defined for the audio here and the duration is set.
167167
const onLoad = (index: string, duration: number) => {
168168
setFilesToDisplay((prevFilesUploads) =>
169-
prevFilesUploads.map((fileUpload, id) => ({
169+
prevFilesUploads.map((fileUpload) => ({
170170
...fileUpload,
171-
duration: id.toString() === index ? duration : fileUpload.duration,
171+
duration: fileUpload.id === index ? duration : fileUpload.duration,
172172
})),
173173
);
174174
};
175175

176176
// The handler which is triggered when the audio progresses/ the thumb is dragged in the progress control. The progressed duration is set here.
177177
const onProgress = (index: string, progress: number) => {
178178
setFilesToDisplay((prevFilesUploads) =>
179-
prevFilesUploads.map((fileUpload, id) => ({
179+
prevFilesUploads.map((fileUpload) => ({
180180
...fileUpload,
181-
progress: id.toString() === index ? progress : fileUpload.progress,
181+
progress: fileUpload.id === index ? progress : fileUpload.progress,
182182
})),
183183
);
184184
};
@@ -188,9 +188,9 @@ const FileUploadPreviewWithContext = <
188188
if (pausedStatus === false) {
189189
// If the status is false we set the audio with the index as playing and the others as paused.
190190
setFilesToDisplay((prevFileUploads) =>
191-
prevFileUploads.map((fileUpload, id) => ({
191+
prevFileUploads.map((fileUpload) => ({
192192
...fileUpload,
193-
paused: id.toString() !== index,
193+
paused: fileUpload.id !== index,
194194
})),
195195
);
196196
} else {
@@ -300,18 +300,9 @@ const FileUploadPreviewWithContext = <
300300
}
301301
}, [fileUploadsLength]);
302302

303-
const memoizedFilesToDisplay = useMemo(
304-
() =>
305-
filesToDisplay.map((file, index) => ({
306-
...file,
307-
id: index.toString(),
308-
})),
309-
[filesToDisplay],
310-
);
311-
312303
return fileUploadsLength ? (
313304
<FlatList
314-
data={memoizedFilesToDisplay}
305+
data={filesToDisplay}
315306
getItemLayout={(_, index) => ({
316307
index,
317308
length: FILE_PREVIEW_HEIGHT + 8,

0 commit comments

Comments
 (0)