microblog/app/posts.tsx

31 lines
856 B
TypeScript
Raw Normal View History

2022-11-06 22:52:29 +01:00
import { getPosts } from '@/lib/getPosts';
import { cookies } from 'next/headers';
import { use } from 'react';
2022-11-06 21:16:09 +01:00
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
2022-11-06 21:07:22 +01:00
2022-11-06 23:17:51 +01:00
export default function Posts() {
2022-11-06 22:52:29 +01:00
const c = cookies();
const posts = use(getPosts());
2022-11-06 21:07:22 +01:00
return (
<>
{posts.map((p) => (
2022-11-06 21:36:43 +01:00
<div className="space-y-2 rounded-md border border-solid border-gray-700 p-4 text-white">
<p className="font-bold">@{p.author.name}</p>
<p className="italic">{p.title}</p>
<div className="markdown">
2022-11-06 21:16:09 +01:00
{p.message && (
<ReactMarkdown children={p.message} remarkPlugins={[remarkGfm]} />
)}
</div>
2022-11-06 21:46:56 +01:00
<small className="mt-2">
{new Date(p.time * 1000).toLocaleString()}
</small>
2022-11-06 21:07:22 +01:00
</div>
))}
</>
);
2022-11-06 23:17:51 +01:00
}