Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regression in file upload preview remove item #2919

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions package/src/components/MessageInput/FileUploadPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { FlatList, I18nManager, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

import { UploadProgressIndicator } from './UploadProgressIndicator';
Expand Down Expand Up @@ -166,19 +166,19 @@ const FileUploadPreviewWithContext = <
// 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.
const onLoad = (index: string, duration: number) => {
setFilesToDisplay((prevFilesUploads) =>
prevFilesUploads.map((fileUpload, id) => ({
prevFilesUploads.map((fileUpload) => ({
...fileUpload,
duration: id.toString() === index ? duration : fileUpload.duration,
duration: fileUpload.id === index ? duration : fileUpload.duration,
})),
);
};

// The handler which is triggered when the audio progresses/ the thumb is dragged in the progress control. The progressed duration is set here.
const onProgress = (index: string, progress: number) => {
setFilesToDisplay((prevFilesUploads) =>
prevFilesUploads.map((fileUpload, id) => ({
prevFilesUploads.map((fileUpload) => ({
...fileUpload,
progress: id.toString() === index ? progress : fileUpload.progress,
progress: fileUpload.id === index ? progress : fileUpload.progress,
})),
);
};
Expand All @@ -188,9 +188,9 @@ const FileUploadPreviewWithContext = <
if (pausedStatus === false) {
// If the status is false we set the audio with the index as playing and the others as paused.
setFilesToDisplay((prevFileUploads) =>
prevFileUploads.map((fileUpload, id) => ({
prevFileUploads.map((fileUpload) => ({
...fileUpload,
paused: id.toString() !== index,
paused: fileUpload.id !== index,
})),
);
} else {
Expand Down Expand Up @@ -300,18 +300,9 @@ const FileUploadPreviewWithContext = <
}
}, [fileUploadsLength]);

const memoizedFilesToDisplay = useMemo(
() =>
filesToDisplay.map((file, index) => ({
...file,
id: index.toString(),
})),
[filesToDisplay],
);

return fileUploadsLength ? (
<FlatList
data={memoizedFilesToDisplay}
data={filesToDisplay}
getItemLayout={(_, index) => ({
index,
length: FILE_PREVIEW_HEIGHT + 8,
Expand Down
Loading