From 4deeef41ea1c48918a952cc44c4c14679d027199 Mon Sep 17 00:00:00 2001 From: Aryan Prince Date: Wed, 7 Feb 2024 22:27:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Removed=20unused=20tRPC?= =?UTF-8?q?=20procedures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/_components/create-post.tsx | 43 ------------------- apps/finance/src/app/page.tsx | 22 ---------- apps/finance/src/server/api/routers/post.ts | 21 --------- .../src/app/_components/create-post.tsx | 43 ------------------- apps/library/src/app/page.tsx | 24 +---------- apps/library/src/server/api/routers/post.ts | 21 --------- 6 files changed, 1 insertion(+), 173 deletions(-) delete mode 100644 apps/finance/src/app/_components/create-post.tsx delete mode 100644 apps/library/src/app/_components/create-post.tsx diff --git a/apps/finance/src/app/_components/create-post.tsx b/apps/finance/src/app/_components/create-post.tsx deleted file mode 100644 index 02d7c38..0000000 --- a/apps/finance/src/app/_components/create-post.tsx +++ /dev/null @@ -1,43 +0,0 @@ -"use client"; - -import { useRouter } from "next/navigation"; -import { useState } from "react"; - -import { api } from "~/trpc/react"; - -export function CreatePost() { - const router = useRouter(); - const [name, setName] = useState(""); - - const createPost = api.post.create.useMutation({ - onSuccess: () => { - router.refresh(); - setName(""); - }, - }); - - return ( -
{ - e.preventDefault(); - createPost.mutate({ name }); - }} - className="flex flex-col gap-2" - > - setName(e.target.value)} - className="w-full rounded-full px-4 py-2 text-black" - /> - -
- ); -} diff --git a/apps/finance/src/app/page.tsx b/apps/finance/src/app/page.tsx index bc55fc1..a42dc38 100644 --- a/apps/finance/src/app/page.tsx +++ b/apps/finance/src/app/page.tsx @@ -1,7 +1,6 @@ import { unstable_noStore as noStore } from "next/cache"; import Link from "next/link"; -import { CreatePost } from "~/app/_components/create-post"; import { getServerAuthSession } from "~/server/auth"; import { api } from "~/trpc/server"; @@ -57,28 +56,7 @@ export default async function Home() { - - ); } - -async function CrudShowcase() { - const session = await getServerAuthSession(); - if (!session?.user) return null; - - const latestPost = await api.post.getLatest.query(); - - return ( -
- {latestPost ? ( -

Your most recent post: {latestPost.name}

- ) : ( -

You have no posts yet.

- )} - - -
- ); -} diff --git a/apps/finance/src/server/api/routers/post.ts b/apps/finance/src/server/api/routers/post.ts index 3994691..82b9400 100644 --- a/apps/finance/src/server/api/routers/post.ts +++ b/apps/finance/src/server/api/routers/post.ts @@ -15,27 +15,6 @@ export const postRouter = createTRPCRouter({ }; }), - create: protectedProcedure - .input(z.object({ name: z.string().min(1) })) - .mutation(async ({ ctx, input }) => { - // simulate a slow db call - await new Promise((resolve) => setTimeout(resolve, 1000)); - - return ctx.db.post.create({ - data: { - name: input.name, - createdBy: { connect: { id: ctx.session.user.id } }, - }, - }); - }), - - getLatest: protectedProcedure.query(({ ctx }) => { - return ctx.db.post.findFirst({ - orderBy: { createdAt: "desc" }, - where: { createdBy: { id: ctx.session.user.id } }, - }); - }), - getSecretMessage: protectedProcedure.query(() => { return "you can now see this secret message!"; }), diff --git a/apps/library/src/app/_components/create-post.tsx b/apps/library/src/app/_components/create-post.tsx deleted file mode 100644 index 02d7c38..0000000 --- a/apps/library/src/app/_components/create-post.tsx +++ /dev/null @@ -1,43 +0,0 @@ -"use client"; - -import { useRouter } from "next/navigation"; -import { useState } from "react"; - -import { api } from "~/trpc/react"; - -export function CreatePost() { - const router = useRouter(); - const [name, setName] = useState(""); - - const createPost = api.post.create.useMutation({ - onSuccess: () => { - router.refresh(); - setName(""); - }, - }); - - return ( -
{ - e.preventDefault(); - createPost.mutate({ name }); - }} - className="flex flex-col gap-2" - > - setName(e.target.value)} - className="w-full rounded-full px-4 py-2 text-black" - /> - -
- ); -} diff --git a/apps/library/src/app/page.tsx b/apps/library/src/app/page.tsx index bc55fc1..1f734eb 100644 --- a/apps/library/src/app/page.tsx +++ b/apps/library/src/app/page.tsx @@ -1,7 +1,6 @@ import { unstable_noStore as noStore } from "next/cache"; import Link from "next/link"; -import { CreatePost } from "~/app/_components/create-post"; import { getServerAuthSession } from "~/server/auth"; import { api } from "~/trpc/server"; @@ -57,28 +56,7 @@ export default async function Home() { - - ); -} - -async function CrudShowcase() { - const session = await getServerAuthSession(); - if (!session?.user) return null; - - const latestPost = await api.post.getLatest.query(); - - return ( -
- {latestPost ? ( -

Your most recent post: {latestPost.name}

- ) : ( -

You have no posts yet.

- )} - - -
- ); -} +} \ No newline at end of file diff --git a/apps/library/src/server/api/routers/post.ts b/apps/library/src/server/api/routers/post.ts index 3994691..82b9400 100644 --- a/apps/library/src/server/api/routers/post.ts +++ b/apps/library/src/server/api/routers/post.ts @@ -15,27 +15,6 @@ export const postRouter = createTRPCRouter({ }; }), - create: protectedProcedure - .input(z.object({ name: z.string().min(1) })) - .mutation(async ({ ctx, input }) => { - // simulate a slow db call - await new Promise((resolve) => setTimeout(resolve, 1000)); - - return ctx.db.post.create({ - data: { - name: input.name, - createdBy: { connect: { id: ctx.session.user.id } }, - }, - }); - }), - - getLatest: protectedProcedure.query(({ ctx }) => { - return ctx.db.post.findFirst({ - orderBy: { createdAt: "desc" }, - where: { createdBy: { id: ctx.session.user.id } }, - }); - }), - getSecretMessage: protectedProcedure.query(() => { return "you can now see this secret message!"; }),