2023-10-21 08:51:33 +02:00
|
|
|
import { createSignal } from "solid-js";
|
|
|
|
import { getPosts } from "./api";
|
|
|
|
import { Post } from "./api";
|
2023-10-27 16:04:58 +02:00
|
|
|
import { useNavigate } from "@solidjs/router";
|
2023-11-13 09:34:32 +01:00
|
|
|
import { Arrow } from "./Icons";
|
2023-10-21 08:51:33 +02:00
|
|
|
|
|
|
|
export function Posts() {
|
|
|
|
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 09:34:32 +01:00
|
|
|
<>
|
|
|
|
{loading() && (
|
2023-10-21 08:51:33 +02:00
|
|
|
<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>;
|
|
|
|
})}
|
2023-11-13 09:34:32 +01:00
|
|
|
</>
|
2023-10-21 08:51:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the card container for a post
|
2023-10-27 16:04:58 +02:00
|
|
|
export function PostSegment({ post }: { post: Post }) {
|
|
|
|
const nav = useNavigate();
|
2023-10-21 08:51:33 +02:00
|
|
|
return (
|
2023-11-13 09:34:32 +01:00
|
|
|
<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">
|
2023-10-21 08:51:33 +02:00
|
|
|
<div class="card-body">
|
2023-10-27 16:04:58 +02:00
|
|
|
<p class="text-base-content break-words">{post?.content}</p>
|
2023-11-13 09:34:32 +01:00
|
|
|
<div class="card-actions justify-end">
|
|
|
|
<button onClick={() => nav("/post/" + post?.id)} class="btn btn-xs">
|
|
|
|
<Arrow />
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-10-21 08:51:33 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-11-13 09:34:32 +01:00
|
|
|
|
|
|
|
|