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