import { Effect } from 'effect'
import { PostsService, RuntimeServer } from '@workspace/api'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@workspace/ui/components/card'
const main = Effect.gen(function* () {
const postsService = yield* PostsService
const allPosts = yield* postsService.getAllPosts
return allPosts
})
export default async function PostsPage() {
const result = await RuntimeServer.runPromise(
main.pipe(
Effect.match({
onFailure: error => {
console.error('Failed to load posts:', error)
return { success: false as const, error: 'Failed to load posts' }
},
onSuccess: postList => ({ success: true as const, data: postList }),
})
)
)
if (!result.success) {
return (
Error: {result.error}
)
}
const posts = result.data
return (
Posts
{posts.map((post) => (
{post.title}
{post.published ? 'Published' : 'Draft'} • {new Date(post.createdAt).toLocaleDateString()}
{post.content && (
{post.content}
)}
))}
{posts.length === 0 && (
No posts found
There are no posts in the database yet.
)}
)
}