2022-12-04 04:55:20 -05:00
|
|
|
import PostList from "@components/post-list"
|
|
|
|
import { getPostsByUser, getUserById } from "@lib/server/prisma"
|
|
|
|
import { Suspense } from "react"
|
|
|
|
|
|
|
|
async function PostListWrapper({
|
|
|
|
posts,
|
2022-12-04 17:26:14 -05:00
|
|
|
userId
|
2022-12-04 04:55:20 -05:00
|
|
|
}: {
|
|
|
|
posts: ReturnType<typeof getPostsByUser>
|
|
|
|
userId: string
|
|
|
|
}) {
|
|
|
|
const data = (await posts).filter((post) => post.visibility === "public")
|
2022-12-04 17:26:14 -05:00
|
|
|
return (
|
|
|
|
<PostList
|
|
|
|
morePosts={false}
|
|
|
|
userId={userId}
|
|
|
|
initialPosts={JSON.stringify(data)}
|
|
|
|
/>
|
|
|
|
)
|
2022-12-04 04:55:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default async function UserPage({
|
|
|
|
params
|
|
|
|
}: {
|
|
|
|
params: {
|
|
|
|
username: string
|
|
|
|
}
|
|
|
|
}) {
|
|
|
|
// TODO: the route should be user.name, not id
|
|
|
|
const id = params.username
|
|
|
|
const user = await getUserById(id)
|
|
|
|
|
|
|
|
const posts = getPostsByUser(id, true)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-12-04 17:49:18 -05:00
|
|
|
<h1>Public posts by {user?.displayName || "Anonymous"}</h1>
|
2022-12-04 04:55:20 -05:00
|
|
|
<Suspense fallback={<PostList initialPosts={JSON.stringify({})} />}>
|
|
|
|
{/* @ts-ignore because TS async JSX support is iffy */}
|
|
|
|
<PostListWrapper posts={posts} userId={id} />
|
|
|
|
</Suspense>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|