43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { useNavigate } from "@solidjs/router";
|
|
import { For, JSXElement, Show, createSignal } from "solid-js";
|
|
|
|
import { Arrow, loadSpinner } from "../Util/Icons";
|
|
import { Post, getPosts } from "../Util/api";
|
|
|
|
export function Posts(): JSXElement {
|
|
const [posts, setPosts] = createSignal([] as Post[]);
|
|
const [loading, setLoading] = createSignal(true);
|
|
|
|
getPosts().then((posts) => {
|
|
setPosts(posts);
|
|
setLoading(false);
|
|
});
|
|
|
|
return (
|
|
<Show when={!loading()} fallback={loadSpinner()}>
|
|
<For each={posts()}>
|
|
{(post): JSXElement => <PostSegment post={post} />}
|
|
</For>
|
|
</Show>
|
|
);
|
|
}
|
|
|
|
// This is the card container for a post
|
|
export function PostSegment(props: { post: Post }): JSXElement {
|
|
const nav = useNavigate();
|
|
return (
|
|
<div class="card compact w-full flex-grow border-b-2 border-b-base-300 bg-base-200 text-base-content transition-all hover:bg-base-300">
|
|
<div class="card-body">
|
|
<p class="break-words text-base-content md:px-6 md:pt-2">{props.post?.content}</p>
|
|
<div class="card-actions justify-end">
|
|
<button
|
|
onClick={(): void => nav("/post/" + props.post?.id)}
|
|
class="btn btn-xs"
|
|
>
|
|
<Arrow />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|