This commit is contained in:
Max Leiter 2022-11-29 22:22:17 -08:00
parent ce0c442273
commit 44a05f6456
3 changed files with 11 additions and 8 deletions

View file

@ -37,7 +37,8 @@ const Post = ({
initialPost?: string initialPost?: string
newPostParent?: string newPostParent?: string
}) => { }) => {
const initialPost = JSON.parse(stringifiedInitialPost || "{}") as PostWithFiles const parsedPost = JSON.parse(stringifiedInitialPost || "{}")
const initialPost = parsedPost?.id ? parsedPost : null
const { setToast } = useToasts() const { setToast } = useToasts()
const router = useRouter() const router = useRouter()
const [title, setTitle] = useState( const [title, setTitle] = useState(

View file

@ -1,5 +1,5 @@
import PageSeo from "@components/page-seo" import PageSeo from "@components/page-seo"
export default function NewPostHead() { export default function NewPostHead() {
return <PageSeo title="Create a new Drift" /> return <PageSeo title="New" />
} }

View file

@ -1,6 +1,6 @@
import PostPage from "app/(posts)/post/[id]/components/post-page" import PostPage from "app/(posts)/post/[id]/components/post-page"
import { notFound, redirect } from "next/navigation" import { notFound, redirect } from "next/navigation"
import { getPostById, Post } from "@lib/server/prisma" import { getAllPosts, getPostById, Post } from "@lib/server/prisma"
import { getCurrentUser } from "@lib/server/session" import { getCurrentUser } from "@lib/server/session"
export type PostProps = { export type PostProps = {
@ -11,7 +11,9 @@ export type PostProps = {
// export async function generateStaticParams() { // export async function generateStaticParams() {
// const posts = await getAllPosts({ // const posts = await getAllPosts({
// where: { // where: {
// visibility: "public" // visibility: {
// in: ["public", "unlisted"]
// }
// } // }
// }) // })
@ -25,12 +27,12 @@ const getPost = async (id: string) => {
withFiles: true, withFiles: true,
withAuthor: true withAuthor: true
}) })
const user = await getCurrentUser()
if (!post) { if (!post) {
return notFound() return notFound()
} }
const user = await getCurrentUser()
const isAuthorOrAdmin = user?.id === post?.authorId || user?.role === "admin" const isAuthorOrAdmin = user?.id === post?.authorId || user?.role === "admin"
if (post.visibility === "public") { if (post.visibility === "public") {