@@ -12,6 +12,7 @@ import {
1212} from "@/components/ui/table" ;
1313import { Badge } from "@/components/ui/badge" ;
1414import { Progress } from "@/components/ui/progress" ;
15+ import { Skeleton } from "@/components/ui/skeleton" ;
1516import { formatDistanceToNow } from 'date-fns' ;
1617
1718type UploadStatus = 'pending' | 'processing' | 'completed' | 'failed' ;
@@ -30,6 +31,7 @@ interface DocumentUpload {
3031
3132export default function DashboardPage ( ) {
3233 const [ uploads , setUploads ] = useState < DocumentUpload [ ] > ( [ ] ) ;
34+ const [ loading , setLoading ] = useState ( false ) ;
3335 const [ isAuthorized , setIsAuthorized ] = useState ( false ) ;
3436 const [ password , setPassword ] = useState ( '' ) ;
3537 const [ error , setError ] = useState ( '' ) ;
@@ -58,11 +60,14 @@ export default function DashboardPage() {
5860
5961 const fetchUploads = async ( ) => {
6062 try {
63+ setLoading ( true ) ;
6164 const response = await fetch ( '/api/admin/uploads' ) ;
6265 const data = await response . json ( ) ;
6366 setUploads ( data ) ;
6467 } catch ( error ) {
6568 console . error ( 'Failed to fetch uploads:' , error ) ;
69+ } finally {
70+ setLoading ( false ) ;
6671 }
6772 } ;
6873
@@ -141,25 +146,39 @@ export default function DashboardPage() {
141146 </ TableRow >
142147 </ TableHeader >
143148 < TableBody >
144- { uploads . map ( ( upload ) => (
145- < TableRow key = { upload . id } >
146- < TableCell className = "font-medium" > { upload . originalFileName } </ TableCell >
147- < TableCell > { getStatusBadge ( upload . status ) } </ TableCell >
148- < TableCell > { formatFileSize ( upload . fileSize ) } </ TableCell >
149- < TableCell >
150- < Progress value = { upload . uploadProgress } className = "w-[100px]" />
151- </ TableCell >
152- < TableCell >
153- < Progress value = { upload . processingProgress } className = "w-[100px]" />
154- </ TableCell >
155- < TableCell >
156- { formatDistanceToNow ( new Date ( upload . createdAt ) , { addSuffix : true } ) }
157- </ TableCell >
158- < TableCell className = "text-red-500" >
159- { upload . error || '-' }
160- </ TableCell >
161- </ TableRow >
162- ) ) }
149+ { loading ? (
150+ [ ...Array ( 5 ) ] . map ( ( _ , index ) => (
151+ < TableRow key = { index } >
152+ < TableCell > < Skeleton className = "h-4 w-40" /> </ TableCell >
153+ < TableCell > < Skeleton className = "h-5 w-20 rounded-full" /> </ TableCell >
154+ < TableCell > < Skeleton className = "h-4 w-16" /> </ TableCell >
155+ < TableCell > < Skeleton className = "h-3 w-[100px]" /> </ TableCell >
156+ < TableCell > < Skeleton className = "h-3 w-[100px]" /> </ TableCell >
157+ < TableCell > < Skeleton className = "h-4 w-24" /> </ TableCell >
158+ < TableCell > < Skeleton className = "h-4 w-8" /> </ TableCell >
159+ </ TableRow >
160+ ) )
161+ ) : (
162+ uploads . map ( ( upload ) => (
163+ < TableRow key = { upload . id } >
164+ < TableCell className = "font-medium" > { upload . originalFileName } </ TableCell >
165+ < TableCell > { getStatusBadge ( upload . status ) } </ TableCell >
166+ < TableCell > { formatFileSize ( upload . fileSize ) } </ TableCell >
167+ < TableCell >
168+ < Progress value = { upload . uploadProgress } className = "w-[100px]" />
169+ </ TableCell >
170+ < TableCell >
171+ < Progress value = { upload . processingProgress } className = "w-[100px]" />
172+ </ TableCell >
173+ < TableCell >
174+ { formatDistanceToNow ( new Date ( upload . createdAt ) , { addSuffix : true } ) }
175+ </ TableCell >
176+ < TableCell className = "text-red-500" >
177+ { upload . error || '-' }
178+ </ TableCell >
179+ </ TableRow >
180+ ) )
181+ ) }
163182 </ TableBody >
164183 </ Table >
165184 </ div >
0 commit comments