FrostByte/client-solid/src/Posts.tsx
2023-11-13 11:50:24 +01:00

46 lines
1.3 KiB
TypeScript

import { createSignal } from "solid-js";
import { getPosts } from "./api";
import { Post } from "./api";
import { useNavigate } from "@solidjs/router";
import { Arrow } from "./Icons";
export function Posts() {
const [posts, setPosts] = createSignal([] as Post[]);
const [loading, setLoading] = createSignal(true);
getPosts().then((posts) => {
setPosts(posts);
setLoading(false);
});
return (
<>
{loading() && (
<span class="loading loading-spinner loading-lg self-center"></span>
)}
{posts().map((post) => {
if (post.content == "") return; // Filtering out empty posts, remove this later
return <PostSegment post={post}></PostSegment>;
})}
</>
);
}
// This is the card container for a post
export function PostSegment({ post }: { post: Post }) {
const nav = useNavigate();
return (
<div class="card border-b-2 flex-grow border-b-base-300 bg-base-200 hover:bg-base-300 compact text-base-content w-full">
<div class="card-body">
<p class="text-base-content break-words">{post?.content}</p>
<div class="card-actions justify-end">
<button onClick={() => nav("/post/" + post?.id)} class="btn btn-xs">
<Arrow />
</button>
</div>
</div>
</div>
);
}