Skip to content

Commit

Permalink
post creation working
Browse files Browse the repository at this point in the history
  • Loading branch information
imonaar committed Jan 16, 2024
1 parent c930f91 commit 81ab08d
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 3 deletions.
192 changes: 189 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.14",
"@editorjs/code": "^2.9.0",
"@editorjs/editorjs": "^2.28.2",
"@editorjs/embed": "^2.7.0",
"@editorjs/header": "^2.8.1",
"@editorjs/image": "^2.9.0",
"@editorjs/inline-code": "^1.5.0",
"@editorjs/link": "^2.6.2",
"@editorjs/list": "^1.9.0",
"@editorjs/table": "^2.3.0",
"@hookform/resolvers": "^3.3.4",
"@prisma/client": "^5.8.0",
"@radix-ui/react-avatar": "^1.0.4",
Expand All @@ -19,6 +28,7 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^5.17.12",
"@uploadthing/react": "^4.1.3",
"axios": "^1.6.5",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
Expand All @@ -33,10 +43,12 @@
"react-hook-form": "^7.49.3",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7",
"uploadthing": "^4.1.3",
"zod": "^3.22.4"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.17.7",
"@types/editorjs__header": "^2.6.3",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
12 changes: 12 additions & 0 deletions src/app/(views)/r/[subredditId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { db } from "@/lib/db"
import { notFound } from "next/navigation"
import { format } from 'date-fns'
import { SubscribeLeaveToggle } from "@/components/subscribe-leave-toggle"
import Link from "next/link"
import { buttonVariants } from "@/components/ui/Button"

export default async function SubredditLayout({ children, params }:
{
Expand Down Expand Up @@ -105,6 +107,16 @@ export default async function SubredditLayout({ children, params }:
isSubscribed={isSubscribed}
/>
) : null}

<Link
href={`${params.subredditId}/submit`}
className={buttonVariants({
variant: 'outline',
className: 'w-full mb-6'
})}
>
Create Post
</Link>
</dl>
</div>
</div>
Expand Down
40 changes: 40 additions & 0 deletions src/app/(views)/r/[subredditId]/submit/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Editor } from "@/components/editor";
import { Button } from "@/components/ui/Button";
import { db } from "@/lib/db"
import { notFound } from "next/navigation"

//poor naming of subredditId params. i should have used slug. Too late to change.

export default async function Create({ params }: {
params: {
subredditId: string
}
}) {
const name = params.subredditId;
const subreddit = await db.subreddit.findFirst({
where: {
name: name
}
})

if (!subreddit) return notFound()

return (
<div className="flex flex-col items-start gap-6">
<div className="border-b border-gray-200">
<div className="-ml-2 -mt-2 flex flex-wrap items-baseline">
<h3 className="ml-2 mt-2 font-semibold leading-6 text-gray-900">Create Post</h3>
<p className="ml-2 mt-1 truncate text-sm text-gray-500">In r/{params.subredditId}</p>
</div>
</div>

{/* form */}

<Editor subredditId={subreddit.id} />

<div className="w-full flex justify-end">
<Button type="submit" className="w-full" form="subreddit-post-form">Post</Button>
</div>
</div>
)
}
Loading

0 comments on commit 81ab08d

Please sign in to comment.