Display a skeleton while guests information is loading
This commit is contained in:
		
							parent
							
								
									611b487db4
								
							
						
					
					
						commit
						4022928f1c
					
				@ -1,8 +1,8 @@
 | 
				
			|||||||
import { lusitana } from '@/app/ui/fonts';
 | 
					import { lusitana } from '@/app/ui/fonts';
 | 
				
			||||||
import AffinityGroupsTree from '@/app/ui/guests/affinity-groups-tree';
 | 
					import AffinityGroupsTree from '@/app/ui/guests/affinity-groups-tree';
 | 
				
			||||||
import GuestsTable from '@/app/ui/guests/table';
 | 
					import GuestsTable from '@/app/ui/guests/table';
 | 
				
			||||||
import { Tree } from 'primereact/tree';
 | 
					import React, { Suspense } from 'react';
 | 
				
			||||||
import React, { useState, useEffect } from 'react';
 | 
					import SkeletonTable from '@/app/ui/guests/skeleton-row';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -10,10 +10,12 @@ export default function Page() {
 | 
				
			|||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="w-full">
 | 
					    <div className="w-full">
 | 
				
			||||||
      <AffinityGroupsTree />
 | 
					      <AffinityGroupsTree />
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      <h1 className={`${lusitana.className} text-2xl py-4`}>Guests</h1>
 | 
					      <h1 className={`${lusitana.className} text-2xl py-4`}>Guests</h1>
 | 
				
			||||||
      <div className="flex w-full items-center justify-between">
 | 
					      <div className="flex w-full items-center justify-between">
 | 
				
			||||||
        <GuestsTable />
 | 
					        <Suspense fallback={<SkeletonTable />}>
 | 
				
			||||||
 | 
					          <GuestsTable />
 | 
				
			||||||
 | 
					        </Suspense>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
import Skeleton from '@/app/ui/skeleton';
 | 
					import Skeleton from '@/app/ui/skeleton';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function SkeletonRow() {
 | 
					export function SkeletonRow() {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <tr className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
 | 
					        <tr className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
 | 
				
			||||||
            <td className="px-6 py-4">{<Skeleton className="w-[45ch] h-[1rem]" />}</td>
 | 
					            <td className="px-6 py-4">{<Skeleton className="w-[45ch] h-[1rem]" />}</td>
 | 
				
			||||||
@ -9,4 +9,26 @@ export default function SkeletonRow() {
 | 
				
			|||||||
            <td className="px-6 py-4">{<Skeleton className="w-[10ch] h-[1rem]" />}</td>
 | 
					            <td className="px-6 py-4">{<Skeleton className="w-[10ch] h-[1rem]" />}</td>
 | 
				
			||||||
        </tr>
 | 
					        </tr>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default function SkeletonTable() {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg">
 | 
				
			||||||
 | 
					            <table className="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
 | 
				
			||||||
 | 
					                <caption className="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white dark:text-white dark:bg-gray-800">
 | 
				
			||||||
 | 
					                    Guests
 | 
				
			||||||
 | 
					                    <p className="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400">
 | 
				
			||||||
 | 
					                        Loading the list of guests...
 | 
				
			||||||
 | 
					                    </p>
 | 
				
			||||||
 | 
					                </caption>
 | 
				
			||||||
 | 
					                <thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
 | 
				
			||||||
 | 
					                </thead>
 | 
				
			||||||
 | 
					                <tbody>
 | 
				
			||||||
 | 
					                    {[...Array(20)].map((e, i) => <SkeletonRow />)}
 | 
				
			||||||
 | 
					                </tbody>
 | 
				
			||||||
 | 
					            </table>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,10 @@ import SkeletonRow from './skeleton-row';
 | 
				
			|||||||
import { Suspense } from 'react';
 | 
					import { Suspense } from 'react';
 | 
				
			||||||
import clsx from 'clsx';
 | 
					import clsx from 'clsx';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function TableHeader() {
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function guestsTable() {
 | 
					export default async function guestsTable() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let guests: Guest[] = await fetch("http://localhost:3001/guests.json")
 | 
					  let guests: Guest[] = await fetch("http://localhost:3001/guests.json")
 | 
				
			||||||
@ -45,36 +49,34 @@ export default async function guestsTable() {
 | 
				
			|||||||
          </tr>
 | 
					          </tr>
 | 
				
			||||||
        </thead>
 | 
					        </thead>
 | 
				
			||||||
        <tbody>
 | 
					        <tbody>
 | 
				
			||||||
          <Suspense fallback={[...Array(20)].map((e, i) => <SkeletonRow />)}>
 | 
					          {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">
 | 
					                {guest.name}
 | 
				
			||||||
                  {guest.name}
 | 
					              </th>
 | 
				
			||||||
                </th>
 | 
					              <td className="px-6 py-4">
 | 
				
			||||||
                <td className="px-6 py-4">
 | 
					                {guest.email}
 | 
				
			||||||
                  {guest.email}
 | 
					              </td>
 | 
				
			||||||
                </td>
 | 
					              <td className="px-6 py-4">
 | 
				
			||||||
                <td className="px-6 py-4">
 | 
					                {guest.group_name}
 | 
				
			||||||
                  {guest.group_name}
 | 
					              </td>
 | 
				
			||||||
                </td>
 | 
					              <td className="px-6 py-4">
 | 
				
			||||||
                <td className="px-6 py-4">
 | 
					                <span className="flex items-center text-sm dark:text-white me-3">
 | 
				
			||||||
                  <span className="flex items-center text-sm dark:text-white me-3">
 | 
					                  <span className={clsx(
 | 
				
			||||||
                    <span className={clsx(
 | 
					                    'flex w-2.5 h-2.5 rounded-full me-1.5 flex-shrink-0',
 | 
				
			||||||
                      'flex w-2.5 h-2.5 rounded-full me-1.5 flex-shrink-0',
 | 
					                    {
 | 
				
			||||||
                      {
 | 
					                      'bg-gray-400': guest.status === 'Considered',
 | 
				
			||||||
                        'bg-gray-400': guest.status === 'Considered',
 | 
					                      'bg-blue-400': guest.status === 'Invited',
 | 
				
			||||||
                        'bg-blue-400': guest.status === 'Invited',
 | 
					                      'bg-green-600': guest.status === 'Confirmed',
 | 
				
			||||||
                        'bg-green-600': guest.status === 'Confirmed',
 | 
					                      'bg-red-400': guest.status === 'Declined',
 | 
				
			||||||
                        'bg-red-400': guest.status === 'Declined',
 | 
					                    }
 | 
				
			||||||
                      }
 | 
					                  )}>
 | 
				
			||||||
                    )}>
 | 
					 | 
				
			||||||
                    </span>
 | 
					 | 
				
			||||||
                    {guest.status}
 | 
					 | 
				
			||||||
                  </span>
 | 
					                  </span>
 | 
				
			||||||
                </td>
 | 
					                  {guest.status}
 | 
				
			||||||
              </tr>
 | 
					                </span>
 | 
				
			||||||
            ))}
 | 
					              </td>
 | 
				
			||||||
          </Suspense>
 | 
					            </tr>
 | 
				
			||||||
 | 
					          ))}
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
      </table>
 | 
					      </table>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user