Skip to content

Commit 43b5115

Browse files
committed
fix: minor fix on file list
1 parent 4ac3b95 commit 43b5115

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/components/Projects/file-list.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import { MoreHorizontal, Trash2, Edit } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import { File as FileType } from '../Foundary/types'
77

8+
const formatFileSize = (bytes?: number | null): string => {
9+
if (!bytes || bytes <= 0) return '0 KB'
10+
const kilobytes = bytes / 1024
11+
if (kilobytes < 1024) {
12+
return `${kilobytes.toFixed(2)} KB`
13+
}
14+
const megabytes = kilobytes / 1024
15+
return `${megabytes.toFixed(2)} MB`
16+
}
17+
818
interface FileListProps {
919
files: FileType[]
1020
onFileClick?: (file: FileType) => void
@@ -47,12 +57,10 @@ export function FileList({
4757
<p className="font-medium">{file.name}</p>
4858
</div>
4959
</div>
50-
<div className="col-span-2 text-sm md:text-base">{file.filesize}</div>
60+
<div className="col-span-2 text-sm md:text-base">{formatFileSize(file.filesize)}</div>
5161
<div className="col-span-2 flex items-center justify-between w-full md:w-auto">
5262
<span className="text-sm md:text-base">
53-
{typeof file.createdAt === 'string'
54-
? file.createdAt
55-
: new Date(file.createdAt).toLocaleDateString()}
63+
{new Date(file.createdAt).toLocaleDateString()}
5664
</span>
5765
<div className="flex gap-1">
5866
{/* <Button

0 commit comments

Comments
 (0)