2022-11-12 01:28:06 -08:00
|
|
|
import NewPost from "../../components/new"
|
2022-11-14 18:39:42 -08:00
|
|
|
import { notFound, redirect } from "next/navigation"
|
2022-11-12 01:28:06 -08:00
|
|
|
import { getPostById } from "@lib/server/prisma"
|
2022-11-14 18:39:42 -08:00
|
|
|
import { getSession } from "@lib/server/session"
|
2022-11-09 23:11:36 -08:00
|
|
|
|
2022-11-09 19:46:12 -08:00
|
|
|
const NewFromExisting = async ({
|
|
|
|
params
|
|
|
|
}: {
|
|
|
|
params: {
|
|
|
|
id: string
|
|
|
|
}
|
|
|
|
}) => {
|
2022-11-14 18:39:42 -08:00
|
|
|
const session = await getSession()
|
|
|
|
if (!session?.user) {
|
|
|
|
return redirect("/signin")
|
|
|
|
}
|
|
|
|
|
2022-11-09 19:46:12 -08:00
|
|
|
const { id } = params
|
|
|
|
|
|
|
|
if (!id) {
|
2022-11-12 16:06:23 -08:00
|
|
|
return notFound()
|
2022-11-09 19:46:12 -08:00
|
|
|
}
|
|
|
|
|
2022-11-14 01:28:40 -08:00
|
|
|
const post = await getPostById(id, {
|
|
|
|
withFiles: true,
|
2022-11-14 17:24:35 -08:00
|
|
|
withAuthor: false
|
2022-11-14 01:28:40 -08:00
|
|
|
})
|
2022-11-09 19:46:12 -08:00
|
|
|
|
2022-11-12 18:39:03 -08:00
|
|
|
return <NewPost initialPost={post} newPostParent={id} />
|
2022-11-09 18:38:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NewFromExisting
|