Slight restructure and breakout of loadingspinner animation

This commit is contained in:
Imbus 2023-11-13 12:10:40 +01:00
parent d3a10b062d
commit 2190833c65
3 changed files with 10 additions and 8 deletions

View file

@ -17,3 +17,7 @@ export function Arrow(): JSXElement {
</svg> </svg>
); );
} }
export function loadSpinner(): JSXElement {
return <span class="loading loading-spinner loading-lg self-center"></span>;
}

View file

@ -1,8 +1,9 @@
import { JSXElement, createSignal } from "solid-js"; import { JSXElement, Show, createSignal } from "solid-js";
import { getPosts } from "./api"; import { getPosts } from "./api";
import { Post } from "./api"; import { Post } from "./api";
import { useNavigate } from "@solidjs/router"; import { useNavigate } from "@solidjs/router";
import { Arrow } from "./Icons"; import { Arrow } from "./Icons";
import { loadSpinner } from "./Icons";
export function Posts(): JSXElement { export function Posts(): JSXElement {
const [posts, setPosts] = createSignal([] as Post[]); const [posts, setPosts] = createSignal([] as Post[]);
@ -14,15 +15,11 @@ export function Posts(): JSXElement {
}); });
return ( return (
<> <Show when={!loading()} fallback={loadSpinner()}>
{loading() && (
<span class="loading loading-spinner loading-lg self-center"></span>
)}
{posts().map((post) => { {posts().map((post) => {
if (post.content == "") return; // Filtering out empty posts, remove this later
return <PostSegment post={post}></PostSegment>; return <PostSegment post={post}></PostSegment>;
})} })}
</> </Show>
); );
} }

View file

@ -2,13 +2,14 @@ import { useParams } from "@solidjs/router";
import { JSXElement, Show, Suspense, createResource } from "solid-js"; import { JSXElement, Show, Suspense, createResource } from "solid-js";
import { getPost } from "./api"; import { getPost } from "./api";
import { PostSegment } from "./Posts"; import { PostSegment } from "./Posts";
import { loadSpinner } from "./Icons";
export function SinglePost(): JSXElement { export function SinglePost(): JSXElement {
const params = useParams(); const params = useParams();
const [post] = createResource(params.postid, getPost); const [post] = createResource(params.postid, getPost);
return ( return (
<Suspense fallback={<div>Some loading message</div>}> <Suspense fallback={loadSpinner()}>
<Show when={post()}> <Show when={post()}>
<PostSegment post={post()!}></PostSegment> <PostSegment post={post()!}></PostSegment>
</Show> </Show>