| 5 | import { seed } from '@/lib/seed' |
| 6 | |
| 7 | export default async function Table() { |
| 8 | let users |
| 9 | let startTime = Date.now() |
| 10 | try { |
| 11 | users = await db.select().from(UsersTable) |
| 12 | } catch (e: any) { |
| 13 | if (e.message === `relation "profiles" does not exist`) { |
| 14 | console.log( |
| 15 | 'Table does not exist, creating and seeding it with dummy data now...' |
| 16 | ) |
| 17 | // Table is not created yet |
| 18 | await seed() |
| 19 | startTime = Date.now() |
| 20 | users = await db.select().from(UsersTable) |
| 21 | } else { |
| 22 | throw e |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | const duration = Date.now() - startTime |
| 27 | |
| 28 | return ( |
| 29 | <div className="bg-white/30 p-12 shadow-xl ring-1 ring-gray-900/5 rounded-lg backdrop-blur-lg max-w-xl mx-auto w-full"> |
| 30 | <div className="flex justify-between items-center mb-4"> |
| 31 | <div className="space-y-1"> |
| 32 | <h2 className="text-xl font-semibold">Recent Users</h2> |
| 33 | <p className="text-sm text-gray-500"> |
| 34 | Fetched {users.length} users in {duration}ms |
| 35 | </p> |
| 36 | </div> |
| 37 | <RefreshButton /> |
| 38 | </div> |
| 39 | <div className="divide-y divide-gray-900/5"> |
| 40 | {users.map((user) => ( |
| 41 | <div |
| 42 | key={user.name} |
| 43 | className="flex items-center justify-between py-3" |
| 44 | > |
| 45 | <div className="flex items-center space-x-4"> |
| 46 | <Image |
| 47 | src={user.image} |
| 48 | alt={user.name} |
| 49 | width={48} |
| 50 | height={48} |
| 51 | className="rounded-full ring-1 ring-gray-900/5" |
| 52 | /> |
| 53 | <div className="space-y-1"> |
| 54 | <p className="font-medium leading-none">{user.name}</p> |
| 55 | <p className="text-sm text-gray-500">{user.email}</p> |
| 56 | </div> |
| 57 | </div> |
| 58 | <p className="text-sm text-gray-500">{timeAgo(user.createdAt)}</p> |
| 59 | </div> |
| 60 | ))} |
| 61 | </div> |
| 62 | </div> |
| 63 | ) |
| 64 | } |