Skip to content

Commit 388416d

Browse files
committed
refactor: simplify AttachmentUploadedSizeIndicator
1 parent 02e973f commit 388416d

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/components/MessageComposer/AttachmentPreviewList/AttachmentUploadedSizeIndicator.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
import React from 'react';
22
import { FileSizeIndicator } from '../../Attachment';
3-
import { prettifyFileSize } from '../hooks/utils';
4-
5-
function formatUploadByteFraction(
6-
uploadPercent: number,
7-
fullBytes: number,
8-
maximumFractionDigits?: number,
9-
): string {
10-
const uploaded = Math.round((uploadPercent / 100) * fullBytes);
11-
return `${prettifyFileSize(uploaded, maximumFractionDigits)} / ${prettifyFileSize(fullBytes, maximumFractionDigits)}`;
12-
}
133

144
function resolveAttachmentFullByteSize(attachment: {
155
file_size?: number | string;
@@ -44,19 +34,20 @@ export const AttachmentUploadedSizeIndicator = ({
4434
}: AttachmentUploadedSizeIndicatorProps) => {
4535
const { uploadProgress, uploadState } = attachment.localMetadata ?? {};
4636
const fullBytes = resolveAttachmentFullByteSize(attachment);
37+
const uploaded =
38+
uploadProgress !== undefined && fullBytes !== undefined
39+
? Math.round((uploadProgress / 100) * fullBytes)
40+
: undefined;
4741

48-
if (
49-
uploadState === 'uploading' &&
50-
uploadProgress !== undefined &&
51-
fullBytes !== undefined
52-
) {
42+
if (uploadState === 'uploading' && uploaded) {
5343
return (
54-
<span
44+
<div
5545
className='str-chat__attachment-preview-file__upload-size-fraction'
5646
data-testid='upload-size-fraction'
5747
>
58-
{formatUploadByteFraction(uploadProgress, fullBytes)}
59-
</span>
48+
<FileSizeIndicator fileSize={uploaded} /> {` / `}
49+
<FileSizeIndicator fileSize={fullBytes} />
50+
</div>
6051
);
6152
}
6253

src/components/MessageComposer/styling/AttachmentPreview.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@
290290
color: var(--accent-primary);
291291
}
292292

293-
.str-chat__attachment-preview-file__upload-size-fraction {
294-
white-space: nowrap;
295-
}
296-
297293
.str-chat__attachment-preview-file__fatal-error {
298294
display: flex;
299295
align-items: center;

0 commit comments

Comments
 (0)