2023-11-15 07:29:59 +01:00
|
|
|
import { For, JSXElement, Show, createSignal } from "solid-js";
|
|
|
|
|
2024-03-12 19:51:41 +01:00
|
|
|
import { loadSpinner } from "../Util/Icons";
|
2023-11-22 15:29:27 +01:00
|
|
|
import { Post, getPosts } from "../Util/api";
|
2024-03-12 19:51:41 +01:00
|
|
|
import { PostSegment } from "./PostSegment";
|
2023-10-21 08:51:33 +02:00
|
|
|
|
2024-03-12 19:51:41 +01: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 (
|
2023-11-13 12:10:40 +01:00
|
|
|
<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>
|
2023-11-13 12:10:40 +01:00
|
|
|
</Show>
|
2023-10-21 08:51:33 +02:00
|
|
|
);
|
|
|
|
}
|