Display a table skeleton while the list of guests is loading #29
| @ -1,31 +1,23 @@ | |||||||
| 'use client' |  | ||||||
| 
 | 
 | ||||||
| import { Guest } from '@/app/lib/definitions'; | import { Guest } from '@/app/lib/definitions'; | ||||||
| import { useState, Suspense, useEffect } from 'react'; | import { useState, Suspense, useEffect } from 'react'; | ||||||
| import clsx from 'clsx'; | import clsx from 'clsx'; | ||||||
| 
 | 
 | ||||||
| export default function guestsTable() { | export default async function guestsTable() { | ||||||
| 
 | 
 | ||||||
|   const [guests, setGuests] = useState<Guest[]>([]); |   let guests: Guest[] = await fetch("http://localhost:3001/guests.json") | ||||||
| 
 |     .then((response) => response.json()) | ||||||
|   useEffect(() => { |     .then((data) => { | ||||||
|     if (guests.length > 0) { |       return data.data.map((record: any) => { | ||||||
|       return; |         return ({ | ||||||
|     } |           id: record.id, | ||||||
|     fetch("http://localhost:3001/guests.json") |           name: record.attributes.name, | ||||||
|       .then((response) => response.json()) |           email: record.attributes.email, | ||||||
|       .then((data) => { |           group_name: record.attributes.group_name, | ||||||
|         setGuests(data.data.map((record: any) => { |           status: record.attributes.status | ||||||
|           return ({ |         }); | ||||||
|             id: record.id, |  | ||||||
|             name: record.attributes.name, |  | ||||||
|             email: record.attributes.email, |  | ||||||
|             group_name: record.attributes.group_name, |  | ||||||
|             status: record.attributes.status |  | ||||||
|           }); |  | ||||||
|         })) |  | ||||||
|       }); |       }); | ||||||
|   }); |     }); | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg"> |     <div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg"> | ||||||
| @ -53,7 +45,7 @@ export default function guestsTable() { | |||||||
|           </tr> |           </tr> | ||||||
|         </thead> |         </thead> | ||||||
|         <tbody> |         <tbody> | ||||||
|           <Suspense> |           <Suspense fallback="<tr><td colspan=4> Loading content</td></tr>"> | ||||||
|             {guests.map((guest) => ( |             {guests.map((guest) => ( | ||||||
|               <tr key={guest.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800"> |               <tr key={guest.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800"> | ||||||
|                 <th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"> |                 <th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user