FrostByte/client-solid/src/Components/Posts.tsx

28 lines
759 B
TypeScript
Raw Normal View History

2023-11-15 07:29:59 +01:00
import { For, JSXElement, Show, createSignal } from "solid-js";
import { loadSpinner } from "../Util/Icons";
2023-11-22 15:29:27 +01:00
import { Post, getPosts } from "../Util/api";
import { PostSegment } from "./PostSegment";
2023-10-21 08:51:33 +02:00
/**
* Posts is a component that displays a collection of posts.
* @returns {JSXElement} A JSXElement that contains a collection of posts.
*/
2023-11-13 12:00:46 +01:00
export function Posts(): JSXElement {
2023-10-21 08:51:33 +02:00
const [posts, setPosts] = createSignal([] as Post[]);
const [loading, setLoading] = createSignal(true);
getPosts().then((posts) => {
2023-11-13 11:50:24 +01:00
setPosts(posts);
2023-10-21 08:51:33 +02:00
setLoading(false);
});
return (
<Show when={!loading()} fallback={loadSpinner()}>
2023-11-15 16:07:04 +01:00
<For each={posts()}>
2023-11-15 07:29:59 +01:00
{(post): JSXElement => <PostSegment post={post} />}
2023-11-15 16:07:04 +01:00
</For>
</Show>
2023-10-21 08:51:33 +02:00
);
}