PostList.tsx 747 B

123456789101112131415161718192021222324252627282930
  1. /** @jsx h */
  2. import { h } from "preact";
  3. interface PostListProps {
  4. posts: { id: string; title: string; content: string; shared: boolean }[];
  5. }
  6. export default function PostList(props: PostListProps) {
  7. const onEdit = (id: string) => {
  8. location.href = `/${id}`;
  9. };
  10. return (
  11. <div className="pd-post-list">
  12. {props.posts.map((post) => (
  13. <div className="pd-post" key={post.id}>
  14. <span className="pd-post-title">{post.title || "Untitled"}</span>
  15. <span className="pd-post-digest">{post.content || "No content"}</span>
  16. <button
  17. onClick={() => {
  18. onEdit(post.id);
  19. }}
  20. >
  21. Edit
  22. </button>
  23. </div>
  24. ))}
  25. </div>
  26. );
  27. }