interface PostListProps { posts: { id: string; title: string; content: string; shared: boolean }[]; } export default function PostList(props: PostListProps) { const onEdit = (id: string) => { location.href = `/${id}`; }; const onDelete = (id: string, title: string) => { window.$modal?.show( "Confirm delete", `Are you sure you want to delete ${title}?`, [ { text: "Confirm", onClick: async () => { const resp = await fetch("/api/post", { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id, }), }); const respJson = await resp.json(); if (respJson.success) { location.reload(); } }, }, { text: "Cancel", }, ], ); }; return (
{props.posts.map((post) => (
{post.title || "Untitled"}
{ onDelete(post.id, post.title); }} />
{post.content || "No content"}
))}
); }