|
1 | 1 | import React from 'react'; |
2 | 2 | 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 | | -} |
13 | 3 |
|
14 | 4 | function resolveAttachmentFullByteSize(attachment: { |
15 | 5 | file_size?: number | string; |
@@ -44,19 +34,20 @@ export const AttachmentUploadedSizeIndicator = ({ |
44 | 34 | }: AttachmentUploadedSizeIndicatorProps) => { |
45 | 35 | const { uploadProgress, uploadState } = attachment.localMetadata ?? {}; |
46 | 36 | const fullBytes = resolveAttachmentFullByteSize(attachment); |
| 37 | + const uploaded = |
| 38 | + uploadProgress !== undefined && fullBytes !== undefined |
| 39 | + ? Math.round((uploadProgress / 100) * fullBytes) |
| 40 | + : undefined; |
47 | 41 |
|
48 | | - if ( |
49 | | - uploadState === 'uploading' && |
50 | | - uploadProgress !== undefined && |
51 | | - fullBytes !== undefined |
52 | | - ) { |
| 42 | + if (uploadState === 'uploading' && uploaded) { |
53 | 43 | return ( |
54 | | - <span |
| 44 | + <div |
55 | 45 | className='str-chat__attachment-preview-file__upload-size-fraction' |
56 | 46 | data-testid='upload-size-fraction' |
57 | 47 | > |
58 | | - {formatUploadByteFraction(uploadProgress, fullBytes)} |
59 | | - </span> |
| 48 | + <FileSizeIndicator fileSize={uploaded} /> {` / `} |
| 49 | + <FileSizeIndicator fileSize={fullBytes} /> |
| 50 | + </div> |
60 | 51 | ); |
61 | 52 | } |
62 | 53 |
|
|
0 commit comments