33import { useState , useRef } from "react" ;
44import { getFileIcon , formatFileSize , formatDate , type FileType } from "../lib/helpers" ;
55import FileItemMenu from "./FileItemMenu" ;
6+ import {
7+ Item ,
8+ ItemActions ,
9+ ItemContent ,
10+ ItemDescription ,
11+ ItemMedia ,
12+ ItemTitle ,
13+ } from "@/components/ui/item" ;
614
715export type { FileType } ;
816
@@ -61,7 +69,7 @@ export default function FileItem({
6169 }
6270
6371 clickCountRef . current += 1 ;
64-
72+
6573 if ( clickCountRef . current === 1 ) {
6674 clickTimeoutRef . current = setTimeout ( ( ) => {
6775 if ( clickCountRef . current === 1 ) {
@@ -88,13 +96,13 @@ export default function FileItem({
8896 setTimeout ( ( ) => {
8997 touchHandledRef . current = false ;
9098 } , 400 ) ;
91-
99+
92100 const currentTime = new Date ( ) . getTime ( ) ;
93101 const tapLength = currentTime - lastTapRef . current ;
94-
102+
95103 if ( tapLength < 300 && tapLength > 0 ) {
96104 // Double tap detected
97-
105+
98106 if ( clickTimeoutRef . current ) {
99107 clearTimeout ( clickTimeoutRef . current ) ;
100108 clickTimeoutRef . current = null ;
@@ -112,18 +120,26 @@ export default function FileItem({
112120 clickTimeoutRef . current = null ;
113121 } , 300 ) ;
114122 }
115-
123+
116124 lastTapRef . current = currentTime ;
117125 } ;
118126
127+ const secondaryLabel =
128+ file . lastModified
129+ ? formatDate ( file . lastModified )
130+ : file . type === "folder"
131+ ? "Folder"
132+ : file . size
133+ ? formatFileSize ( file . size )
134+ : "File" ;
135+
119136 if ( view === "grid" ) {
120137 return (
121- < section
122- className = { `group relative flex cursor-pointer select-none flex-col items-center justify-center rounded-lg border-2 p-2 transition-colors sm:p-4 ${ isSelected
123- ? "border-primary bg-accent"
124- : "border-transparent bg-background hover:border-border hover:bg-muted"
125- } `}
126- style = { { touchAction : 'manipulation' } }
138+ < Item
139+ variant = { isSelected ? "muted" : "outline" }
140+ size = "default"
141+ className = "relative h-full cursor-pointer select-none flex-col items-center justify-center gap-3 py-5 text-center hover:bg-muted"
142+ style = { { touchAction : "manipulation" } }
127143 onMouseEnter = { ( ) => setIsHovered ( true ) }
128144 onMouseLeave = { ( ) => setIsHovered ( false ) }
129145 onClick = { handleClick }
@@ -138,34 +154,42 @@ export default function FileItem({
138154 } }
139155 >
140156 { isHovered && (
141- < FileItemMenu
142- file = { file }
143- position = "top-right"
144- onRename = { onRename }
145- onPreview = { onPreview }
146- onDownload = { onDownload }
147- onCopy = { onCopy }
148- onMove = { onMove }
149- onDelete = { onDelete }
150- onShare = { onShare }
151- />
157+ < ItemActions className = "absolute top-1.5 right-1.5 z-10" >
158+ < FileItemMenu
159+ file = { file }
160+ position = "top-right"
161+ onRename = { onRename }
162+ onPreview = { onPreview }
163+ onDownload = { onDownload }
164+ onCopy = { onCopy }
165+ onMove = { onMove }
166+ onDelete = { onDelete }
167+ onShare = { onShare }
168+ />
169+ </ ItemActions >
152170 ) }
153- < div className = "mb-1 flex h-12 w-12 items-center justify-center sm:mb-2 sm:h-16 sm:w -16" >
171+ < ItemMedia className = "mb-0 flex size-14 items-center justify-center rounded-2xl bg-muted sm:size -16" >
154172 { getFileIcon ( file . type , file . mimeType ) }
155- </ div >
156- < p className = "max-w-full truncate text-center text-xs font-medium text-foreground sm:text-sm" >
157- { file . name }
158- </ p >
159- </ section >
173+ </ ItemMedia >
174+ < ItemContent className = "w-full min-w-0 items-center gap-0.5" >
175+ < ItemTitle className = "w-full justify-center truncate text-xs sm:text-sm" >
176+ { file . name }
177+ </ ItemTitle >
178+ < ItemDescription className = "line-clamp-1 w-full text-center text-xs" >
179+ { secondaryLabel }
180+ </ ItemDescription >
181+ </ ItemContent >
182+ </ Item >
160183 ) ;
161184 }
162185
163186 // List view
164187 return (
165- < section
166- className = { `group flex cursor-pointer select-none items-center gap-2 border-b border-border px-2 py-2 transition-colors sm:gap-4 sm:px-4 sm:py-3 ${ isSelected ? "bg-accent" : "bg-background hover:bg-muted"
167- } `}
168- style = { { touchAction : 'manipulation' } }
188+ < Item
189+ variant = { isSelected ? "muted" : "outline" }
190+ size = "sm"
191+ className = "cursor-pointer select-none hover:bg-muted"
192+ style = { { touchAction : "manipulation" } }
169193 onMouseEnter = { ( ) => setIsHovered ( true ) }
170194 onMouseLeave = { ( ) => setIsHovered ( false ) }
171195 onClick = { handleClick }
@@ -179,32 +203,39 @@ export default function FileItem({
179203 onContextMenu ?.( file , event ) ;
180204 } }
181205 >
182- < div className = "flex h-8 w-8 flex-shrink-0 items-center justify-center sm:h-10 sm:w -10" >
206+ < ItemMedia className = "flex size-9 items-center justify-center rounded-xl bg-muted sm:size -10" >
183207 { getFileIcon ( file . type , file . mimeType ) }
184- </ div >
185- < div className = "min-w-0 flex-1" >
186- < p className = "truncate text-xs font-medium text-foreground sm:text-sm" > { file . name } </ p >
187- </ div >
188- < div className = "hidden flex-shrink-0 text-xs text-muted-foreground sm:block sm:text-sm" >
189- { file . lastModified && formatDate ( file . lastModified ) }
190- </ div >
191- < div className = "hidden flex-shrink-0 text-xs text-muted-foreground md:block md:text-sm" >
192- { file . size && formatFileSize ( file . size ) }
193- </ div >
208+ </ ItemMedia >
209+
210+ < ItemContent className = "min-w-0 gap-0.5" >
211+ < ItemTitle className = "w-full truncate" > { file . name } </ ItemTitle >
212+ < ItemDescription className = "line-clamp-1 text-xs" >
213+ { secondaryLabel }
214+ </ ItemDescription >
215+ </ ItemContent >
216+
217+ < ItemActions className = "ml-auto hidden min-w-20 shrink-0 justify-end text-muted-foreground md:flex" >
218+ < span className = "text-xs sm:text-sm" >
219+ { file . size ? formatFileSize ( file . size ) : file . type === "folder" ? "—" : "" }
220+ </ span >
221+ </ ItemActions >
222+
194223 { isHovered && (
195- < FileItemMenu
196- file = { file }
197- position = "right"
198- onRename = { onRename }
199- onPreview = { onPreview }
200- onDownload = { onDownload }
201- onCopy = { onCopy }
202- onMove = { onMove }
203- onDelete = { onDelete }
204- onShare = { onShare }
205- />
224+ < ItemActions className = "shrink-0" >
225+ < FileItemMenu
226+ file = { file }
227+ position = "right"
228+ onRename = { onRename }
229+ onPreview = { onPreview }
230+ onDownload = { onDownload }
231+ onCopy = { onCopy }
232+ onMove = { onMove }
233+ onDelete = { onDelete }
234+ onShare = { onShare }
235+ />
236+ </ ItemActions >
206237 ) }
207- </ section >
238+ </ Item >
208239 ) ;
209240}
210241
0 commit comments