fix write
This commit is contained in:
		| @@ -1,8 +1,8 @@ | |||||||
| import { notFound, redirect } from "next/navigation"; | import { notFound, redirect } from "next/navigation"; | ||||||
| import { getPost } from "../../action"; |  | ||||||
| import { Post } from "../../types"; | import { Post } from "../../types"; | ||||||
| import Write from "../Write"; | import Write from "../Write"; | ||||||
| import { isLoggedIn } from "@/components/auth"; | import { isLoggedIn } from "@/components/auth"; | ||||||
|  | import { PrismaClient } from "@prisma/client"; | ||||||
|  |  | ||||||
| export default async function WritePage({ | export default async function WritePage({ | ||||||
|   params, |   params, | ||||||
| @@ -16,10 +16,20 @@ export default async function WritePage({ | |||||||
|   const slug = (await params).slug?.[0]; |   const slug = (await params).slug?.[0]; | ||||||
|   let post: Post | undefined = undefined; |   let post: Post | undefined = undefined; | ||||||
|   if (slug) { |   if (slug) { | ||||||
|     post = (await getPost(slug)) ?? undefined; |     const prisma = new PrismaClient(); | ||||||
|     if (post == null) { |     const result = | ||||||
|  |       (await prisma.post.findUnique({ | ||||||
|  |         where: { slug }, | ||||||
|  |         include: { tags: true }, | ||||||
|  |       })) ?? undefined; | ||||||
|  |     if (result == null) { | ||||||
|       notFound(); |       notFound(); | ||||||
|     } |     } | ||||||
|  |     post = { | ||||||
|  |       ...result, | ||||||
|  |       tags: result.tags.map((tag) => tag.name), | ||||||
|  |       contentRendered: result.contentRendered as { __html: string }, | ||||||
|  |     }; | ||||||
|   } |   } | ||||||
|   return <Write post={post} />; |   return <Write post={post} />; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user