import React, { useState, useEffect } from 'react'; import { getDirectusClient, readItems } from '@/lib/directus/client'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; // Need to implement Table? Or use grid. // Assume Table isn't fully ready or use Grid for now to be safe. import { Card } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Post } from '@/types/schema'; export default function PostList() { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function load() { try { const client = getDirectusClient(); // @ts-ignore const data = await client.request(readItems('posts', { fields: ['*', 'site.name', 'author.name'], limit: 50 })); setPosts(data as unknown as Post[]); } catch (e) { console.error(e); } finally { setLoading(false); } } load(); }, []); if (loading) return
Loading...
; return (
{posts.map(post => ( ))} {posts.length === 0 && ( )}
Title Site Status Date
{post.title}
{post.slug}
{/* @ts-ignore */} {post.site?.name || '-'} {post.status} {new Date(post.date_created || '').toLocaleDateString()}
No posts found.
); }