CoastalCommitsPastes/client/app/page.tsx

70 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-12-04 17:49:18 -05:00
import Image from "next/image"
import Card from "@components/card"
2022-11-09 21:38:05 -05:00
import { getWelcomeContent } from "pages/api/welcome"
2022-12-04 17:49:18 -05:00
import DocumentTabs from "./(posts)/components/tabs"
import { getAllPosts, Post } from "@lib/server/prisma"
import PostList from "@components/post-list"
2022-11-09 21:38:05 -05:00
const getWelcomeData = async () => {
const welcomeContent = await getWelcomeContent()
return welcomeContent
}
export default async function Page() {
2022-11-10 02:11:36 -05:00
const { content, rendered, title } = await getWelcomeData()
2022-12-04 17:49:18 -05:00
const getPostsPromise = getAllPosts({
where: { visibility: "public" }
})
2022-11-12 03:58:21 -05:00
return (
2022-12-04 17:49:18 -05:00
<div
style={{ display: "flex", flexDirection: "column", gap: "var(--gap)" }}
>
<div
style={{ display: "flex", flexDirection: "row", alignItems: "center" }}
>
<Image
src={"/assets/logo-optimized.svg"}
width={48}
height={48}
alt=""
priority
/>
<h1 style={{ marginLeft: "var(--gap)" }}>{title}</h1>
</div>
<Card>
<DocumentTabs
defaultTab="preview"
isEditing={false}
content={content}
preview={rendered as string}
title={title}
/>
</Card>
<div>
<h2>Recent public posts</h2>
{/* @ts-ignore because of async RSC */}
<PublicPostList getPostsPromise={getPostsPromise} />
</div>
</div>
)
}
async function PublicPostList({
getPostsPromise
}: {
getPostsPromise: Promise<Post[]>
}) {
const posts = await getPostsPromise
return (
<PostList
userId={undefined}
morePosts={false}
initialPosts={JSON.stringify(posts)}
hideSearch
2022-11-12 21:39:03 -05:00
/>
)
2022-11-09 01:14:43 -05:00
}
2022-12-04 17:49:18 -05:00
export const revalidate = 60