@@ -5,6 +5,7 @@ import { File as FileIcon, Trash2, Copy } from "lucide-react";
55import { uploadMediaAction , deleteMediaAction } from "../../lib/media-actions" ;
66import type { MediaFile } from "../../lib/types" ;
77import { runAction } from "./runAction" ;
8+ import { ResourceCard , NewResourceCard , formatRelativeTime } from "./ResourceCard" ;
89
910function formatFileSize ( bytes : number ) : string {
1011 if ( bytes < 1024 ) return `${ bytes } B` ;
@@ -21,31 +22,25 @@ function UploadCard({
2122} ) {
2223 const inputRef = useRef < HTMLInputElement > ( null ) ;
2324
24- function handleChange ( e : React . ChangeEvent < HTMLInputElement > ) {
25- const file = e . target . files ?. [ 0 ] ;
26- if ( file ) onFileSelected ( file ) ;
27- e . target . value = "" ;
28- }
29-
3025 return (
31- < button
32- type = "button "
33- onClick = { ( ) => inputRef . current ?. click ( ) }
26+ < NewResourceCard
27+ label = "Upload File "
28+ loadingLabel = "Uploading..."
3429 disabled = { disabled }
35- className = "flex h-48 w-32 shrink-0 cursor-pointer rounded-lg flex-col items-center justify-center border border-dashed border-gray-400 bg-white p-4 text-center text-gray-700 transition-colors hover:bg-gray-50 hover:text-gray-900 disabled:cursor-not-allowed disabled:opacity-60"
30+ onClick = { ( ) => inputRef . current ?. click ( ) }
3631 >
37- < span className = "text-3xl leading-none" > +</ span >
38- < span className = "mt-2 text-sm font-medium" >
39- { disabled ? "Uploading..." : "Upload File" }
40- </ span >
4132 < input
4233 ref = { inputRef }
4334 type = "file"
4435 hidden
45- onChange = { handleChange }
36+ onChange = { ( e ) => {
37+ const file = e . target . files ?. [ 0 ] ;
38+ if ( file ) onFileSelected ( file ) ;
39+ e . target . value = "" ;
40+ } }
4641 disabled = { disabled }
4742 />
48- </ button >
43+ </ NewResourceCard >
4944 ) ;
5045}
5146
@@ -59,37 +54,28 @@ function MediaCard({
5954 disabled : boolean ;
6055} ) {
6156 const isImage = file . contentType ?. startsWith ( "image/" ) ;
62-
63- function handleCopyUrl ( ) {
64- navigator . clipboard . writeText ( file . url ) ;
65- }
57+ const createdDate = file . createdAt ? formatRelativeTime ( new Date ( file . createdAt ) ) : null ;
6658
6759 return (
68- < div className = "flex h-48 w-32 shrink-0 flex-col rounded-lg bg-gray-100 overflow-hidden" >
69- < div className = "flex h-28 items-center justify-center bg-gray-200" >
70- { isImage ? (
60+ < ResourceCard
61+ preview = {
62+ isImage ? (
7163 < img
7264 src = { file . url }
7365 alt = { file . name }
7466 className = "h-full w-full object-cover"
7567 />
7668 ) : (
7769 < FileIcon className = "h-10 w-10 text-gray-400" />
78- ) }
79- </ div >
80-
81- < div className = "flex flex-1 flex-col p-2" >
82- < span className = "truncate text-xs font-medium" title = { file . name } >
83- { file . name }
84- </ span >
85- < span className = "text-xs text-gray-500" >
86- { formatFileSize ( file . size ) }
87- </ span >
88-
89- < div className = "mt-auto flex gap-1" >
70+ )
71+ }
72+ name = { file . name }
73+ date = { createdDate ? `${ createdDate } \u00B7 ${ formatFileSize ( file . size ) } ` : formatFileSize ( file . size ) }
74+ actions = {
75+ < >
9076 < button
9177 type = "button"
92- onClick = { handleCopyUrl }
78+ onClick = { ( ) => navigator . clipboard . writeText ( file . url ) }
9379 className = "rounded p-1 text-gray-500 hover:text-blue-600"
9480 title = "Copy URL"
9581 >
@@ -104,9 +90,9 @@ function MediaCard({
10490 >
10591 < Trash2 className = "h-3 w-3" />
10692 </ button >
107- </ div >
108- </ div >
109- </ div >
93+ </ >
94+ }
95+ / >
11096 ) ;
11197}
11298
0 commit comments