diff --git a/src/app/_components/post.tsx b/src/app/_components/post.tsx deleted file mode 100644 index cf74fac7..00000000 --- a/src/app/_components/post.tsx +++ /dev/null @@ -1,55 +0,0 @@ -'use client' - -import { useState } from 'react' - -import { api } from '~/trpc/react' - -export function LatestPost() { - const [latestPost] = api.post.getLatest.useSuspenseQuery() - - const utils = api.useUtils() - const [name, setName] = useState('') - const createPost = api.post.create.useMutation({ - onSuccess: async () => { - await utils.post.invalidate() - setName('') - }, - }) - - return ( -
- {latestPost - ? ( -

- Your most recent post: - {latestPost.name} -

- ) - : ( -

You have no posts yet.

- )} -
{ - 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/src/server/api/routers/post.ts b/src/server/api/routers/post.ts deleted file mode 100644 index 463e06f7..00000000 --- a/src/server/api/routers/post.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { z } from 'zod' - -import { - createTRPCRouter, - protectedProcedure, - publicProcedure, -} from '~/server/api/trpc' - -export const postRouter = createTRPCRouter({ - hello: publicProcedure - .input(z.object({ text: z.string() })) - .query(({ input }) => { - return { - greeting: `Hello ${input.text}`, - } - }), - - create: protectedProcedure - .input(z.object({ name: z.string().min(1) })) - .mutation(async ({ ctx, input }) => { - await new Promise(resolve => setTimeout(resolve, 1000)) // simulate a slow db call - - 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!' - }), -})