import { useParams } from "@solidjs/router";
import { JSXElement, Show, Suspense, createResource } from "solid-js";

import { loadSpinner } from "./Icons";
import { PostSegment } from "./Posts";
import { getPost } from "./api";

export function SinglePost(): JSXElement {
  const params = useParams();
  const [post] = createResource(params.postid, getPost);

  return (
    <Suspense fallback={loadSpinner()}>
      <Show when={post()}>
        <PostSegment post={post()!} />
      </Show>
    </Suspense>
  );
}
