Compare commits
	
		
			2 Commits
		
	
	
		
			59422c5f67
			...
			2eb60f12a0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2eb60f12a0 | |||
| a661d6e690 | 
| @@ -146,13 +146,34 @@ export default function PostDisplay({ | ||||
|       <div | ||||
|         style={{ | ||||
|           display: "flex", | ||||
|           justifyContent: "flex-end", | ||||
|           justifyContent: "space-between", | ||||
|           marginTop: "1rem", | ||||
|           userSelect: "none", | ||||
|           cursor: "pointer", | ||||
|           backgroundColor: "transparent", | ||||
|         }} | ||||
|       > | ||||
|         {loggedIn ? ( | ||||
|           <div | ||||
|             style={{ | ||||
|               backgroundColor: "#a66", | ||||
|               color: "#111", | ||||
|               fontSize: "0.8rem", | ||||
|               padding: "0.5rem", | ||||
|               transition: "background-color 0.3s linear", | ||||
|               userSelect: "none", | ||||
|               cursor: "pointer", | ||||
|             }} | ||||
|             onMouseOver={(e) => { | ||||
|               e.currentTarget.style.backgroundColor = "#c88"; | ||||
|             }} | ||||
|             onMouseOut={(e) => { | ||||
|               e.currentTarget.style.backgroundColor = "#a66"; | ||||
|             }} | ||||
|             onClick={() => router.push(`/blog/write/${post.slug}`)} | ||||
|           > | ||||
|             edit | ||||
|           </div> | ||||
|         ) : ( | ||||
|           <div></div> | ||||
|         )} | ||||
|         <span | ||||
|           style={{ | ||||
|             backgroundColor: "#999", | ||||
| @@ -160,6 +181,8 @@ export default function PostDisplay({ | ||||
|             fontSize: "0.8rem", | ||||
|             padding: "0.5rem", | ||||
|             transition: "background-color 0.3s linear", | ||||
|             userSelect: "none", | ||||
|             cursor: "pointer", | ||||
|           }} | ||||
|           onMouseOver={(e) => { | ||||
|             e.currentTarget.style.backgroundColor = "#eee"; | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| import { notFound, redirect } from "next/navigation"; | ||||
| import { getPost } from "../../action"; | ||||
| import { Post } from "../../types"; | ||||
| import Write from "../Write"; | ||||
| import { isLoggedIn } from "@/components/auth"; | ||||
| import { PrismaClient } from "@prisma/client"; | ||||
|  | ||||
| export default async function WritePage({ | ||||
|   params, | ||||
| @@ -16,10 +16,20 @@ export default async function WritePage({ | ||||
|   const slug = (await params).slug?.[0]; | ||||
|   let post: Post | undefined = undefined; | ||||
|   if (slug) { | ||||
|     post = (await getPost(slug)) ?? undefined; | ||||
|     if (post == null) { | ||||
|     const prisma = new PrismaClient(); | ||||
|     const result = | ||||
|       (await prisma.post.findUnique({ | ||||
|         where: { slug }, | ||||
|         include: { tags: true }, | ||||
|       })) ?? undefined; | ||||
|     if (result == null) { | ||||
|       notFound(); | ||||
|     } | ||||
|     post = { | ||||
|       ...result, | ||||
|       tags: result.tags.map((tag) => tag.name), | ||||
|       contentRendered: result.contentRendered as { __html: string }, | ||||
|     }; | ||||
|   } | ||||
|   return <Write post={post} />; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user