Skip to content

Commit 7e653a4

Browse files
Adding file size to file attachment
1 parent 5c796c4 commit 7e653a4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

native-package/src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ registerNativeHandlers({
5454

5555
return {
5656
cancelled: false,
57-
docs: res.map(({ name, uri }) => ({ name, uri })),
57+
docs: res.map(({ name, size, type, uri }) => ({
58+
name,
59+
size,
60+
type,
61+
uri,
62+
})),
5863
};
5964
} catch (err) {
6065
return {

src/components/Attachment/FileAttachment.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ const goToURL = (url) => {
5151
});
5252
};
5353

54+
const getFileSizeDisplayText = (size) => {
55+
if (!size) return;
56+
57+
if (size < 1000) {
58+
return `${size} KB`;
59+
}
60+
61+
if (size < 1000 * 1000) {
62+
return `${size / 1000} MB`;
63+
}
64+
65+
return `${size / (1000 * 1000)} GB`;
66+
};
67+
5468
const FileAttachment = ({
5569
actionHandler,
5670
alignment,
@@ -78,7 +92,7 @@ const FileAttachment = ({
7892
/>
7993
<FileDetails>
8094
<FileTitle numberOfLines={2}>{attachment.title}</FileTitle>
81-
<FileSize>{attachment.file_size} KB</FileSize>
95+
<FileSize>{getFileSizeDisplayText(attachment.file_size)}</FileSize>
8296
</FileDetails>
8397
</FileContainer>
8498
{attachment.actions && attachment.actions.length ? (

0 commit comments

Comments
 (0)