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

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-10-27 16:04:58 +02:00
import { useNavigate } from "@solidjs/router";
2023-11-15 07:29:59 +01:00
import { For, JSXElement, Show, createSignal } from "solid-js";
import { Arrow, EngagementIcon, loadSpinner } from "../Util/Icons";
2023-11-22 15:29:27 +01:00
import { Post, getPosts } from "../Util/api";
2023-10-21 08:51:33 +02:00
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
);
}
// This is the card container for a post
2024-03-12 18:33:08 +01:00
export function PostSegment({ post } : { post: Post }): JSXElement {
2023-10-27 16:04:58 +02:00
const nav = useNavigate();
2024-03-12 18:33:08 +01:00
2023-10-21 08:51:33 +02:00
return (
<div class="card compact w-full flex-grow border-b-2 border-b-primary bg-base-200 text-base-content transition-all hover:bg-base-300">
<div class="card-body md:mx-6">
2024-03-12 18:33:08 +01:00
<h3>
{post.createdAt ?? "No Creation Date"}
</h3>
<p class="break-words text-base-content md:pt-2">
2024-03-12 18:33:08 +01:00
{post.content}
</p>
<div class="card-actions justify-between">
<button
// onClick={(engagement)}
class="btn btn-xs hover:border-x-primary"
2024-03-12 18:33:08 +01:00
aria-label="Show sign of engagement"
>
<EngagementIcon />
</button>
2023-11-13 12:00:46 +01:00
<button
2024-03-12 18:33:08 +01:00
onClick={(): void => nav("/post/" + post.id)}
2023-11-13 12:00:46 +01:00
class="btn btn-xs"
2024-03-08 06:06:15 +01:00
aria-label="View post"
2023-11-13 12:00:46 +01:00
>
2023-11-13 09:34:32 +01:00
<Arrow />
</button>
</div>
2023-10-21 08:51:33 +02:00
</div>
</div>
);
}