2022-11-11 23:59:33 -08:00
|
|
|
import { redirect } from "next/navigation"
|
2022-12-04 01:31:51 -08:00
|
|
|
import { getPostsByUser, User } from "@lib/server/prisma"
|
2022-11-12 01:28:06 -08:00
|
|
|
import PostList from "@components/post-list"
|
2022-11-11 19:17:44 -08:00
|
|
|
import { getCurrentUser } from "@lib/server/session"
|
|
|
|
import { authOptions } from "@lib/server/auth"
|
2022-12-04 01:31:51 -08:00
|
|
|
import { cache } from "react"
|
|
|
|
|
|
|
|
const cachedGetPostsByUser = cache(
|
|
|
|
async (userId: User["id"]) => await getPostsByUser(userId, true)
|
|
|
|
)
|
2022-11-11 16:33:43 -08:00
|
|
|
|
2022-11-09 23:11:36 -08:00
|
|
|
export default async function Mine() {
|
2022-11-11 19:17:44 -08:00
|
|
|
const userId = (await getCurrentUser())?.id
|
|
|
|
|
2022-11-09 23:11:36 -08:00
|
|
|
if (!userId) {
|
2022-11-12 01:57:30 -08:00
|
|
|
return redirect(authOptions.pages?.signIn || "/new")
|
2022-11-09 23:11:36 -08:00
|
|
|
}
|
|
|
|
|
2022-12-04 01:31:51 -08:00
|
|
|
const posts = await cachedGetPostsByUser(userId)
|
2022-11-11 19:17:44 -08:00
|
|
|
|
2022-11-09 23:11:36 -08:00
|
|
|
const hasMore = false
|
2022-11-13 23:02:31 -08:00
|
|
|
const stringifiedPosts = JSON.stringify(posts)
|
2022-11-17 22:36:53 -08:00
|
|
|
return (
|
|
|
|
<PostList
|
|
|
|
userId={userId}
|
|
|
|
morePosts={hasMore}
|
|
|
|
initialPosts={stringifiedPosts}
|
|
|
|
/>
|
|
|
|
)
|
2022-11-09 23:11:36 -08:00
|
|
|
}
|