From a97cfe90b6b5c682d76b470983ab4e669ac106a4 Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Wed, 13 Sep 2023 19:47:02 +0200 Subject: [PATCH] drop unique constraint --- cli/template/extras/prisma/schema/with-auth.prisma | 2 ++ cli/template/extras/src/app/_components/create-post.tsx | 8 +++++--- cli/template/extras/src/server/db/drizzle-schema-auth.ts | 3 +-- cli/template/extras/src/server/db/drizzle-schema-base.ts | 3 +-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/template/extras/prisma/schema/with-auth.prisma b/cli/template/extras/prisma/schema/with-auth.prisma index 8070876c1c..ecb699e630 100644 --- a/cli/template/extras/prisma/schema/with-auth.prisma +++ b/cli/template/extras/prisma/schema/with-auth.prisma @@ -22,6 +22,8 @@ model Post { createdBy User @relation(fields: [createdById], references: [id]) createdById String + + @@index([text]) } // Necessary for Next auth diff --git a/cli/template/extras/src/app/_components/create-post.tsx b/cli/template/extras/src/app/_components/create-post.tsx index f4f01c17f1..47024509bb 100644 --- a/cli/template/extras/src/app/_components/create-post.tsx +++ b/cli/template/extras/src/app/_components/create-post.tsx @@ -1,15 +1,18 @@ "use client"; import { useRouter } from "next/navigation"; +import { useState } from "react"; import { api } from "~/trpc/react"; export function CreatePost() { const router = useRouter(); + const [text, setText] = useState(""); const createPost = api.post.create.useMutation({ onSuccess: () => { router.refresh(); + setText(""); }, }); @@ -17,16 +20,15 @@ export function CreatePost() {
{ e.preventDefault(); - - const text = new FormData(e.currentTarget).get("text") as string; createPost.mutate({ text }); }} className="flex flex-col gap-2" > setText(e.target.value)} className="w-full rounded-full px-4 py-2 text-black" />