Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fc0756
commit 45ca025
Showing
3 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
"use client"; | ||
// "use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { useState } from "react"; | ||
// import { useRouter } from "next/navigation"; | ||
// import { useState } from "react"; | ||
|
||
import { api } from "~/trpc/react"; | ||
// import { api } from "~/trpc/react"; | ||
|
||
export function CreatePost() { | ||
const router = useRouter(); | ||
const [name, setName] = useState(""); | ||
// export function CreatePost() { | ||
// const router = useRouter(); | ||
// const [name, setName] = useState(""); | ||
|
||
const createPost = api.post.create.useMutation({ | ||
onSuccess: () => { | ||
router.refresh(); | ||
setName(""); | ||
}, | ||
}); | ||
// const createPost = api.post.create.useMutation({ | ||
// onSuccess: () => { | ||
// router.refresh(); | ||
// setName(""); | ||
// }, | ||
// }); | ||
|
||
return ( | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
createPost.mutate({ name }); | ||
}} | ||
className="flex flex-col gap-2" | ||
> | ||
<input | ||
type="text" | ||
placeholder="Title" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
className="w-full rounded-full px-4 py-2 text-black" | ||
/> | ||
<button | ||
type="submit" | ||
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20" | ||
disabled={createPost.isLoading} | ||
> | ||
{createPost.isLoading ? "Submitting..." : "Submit"} | ||
</button> | ||
</form> | ||
); | ||
} | ||
// return ( | ||
// <form | ||
// onSubmit={(e) => { | ||
// e.preventDefault(); | ||
// createPost.mutate({ name }); | ||
// }} | ||
// className="flex flex-col gap-2" | ||
// > | ||
// <input | ||
// type="text" | ||
// placeholder="Title" | ||
// value={name} | ||
// onChange={(e) => setName(e.target.value)} | ||
// className="w-full rounded-full px-4 py-2 text-black" | ||
// /> | ||
// <button | ||
// type="submit" | ||
// className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20" | ||
// disabled={createPost.isLoading} | ||
// > | ||
// {createPost.isLoading ? "Submitting..." : "Submit"} | ||
// </button> | ||
// </form> | ||
// ); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { z } from "zod"; | ||
// import { z } from "zod"; | ||
|
||
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; | ||
import { posts } from "~/server/db/schema"; | ||
// import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; | ||
// import { posts } from "~/server/db/schema"; | ||
|
||
export const postRouter = createTRPCRouter({ | ||
hello: publicProcedure | ||
.input(z.object({ text: z.string() })) | ||
.query(({ input }) => { | ||
return { | ||
greeting: `Hello ${input.text}`, | ||
}; | ||
}), | ||
// export const postRouter = createTRPCRouter({ | ||
// hello: publicProcedure | ||
// .input(z.object({ text: z.string() })) | ||
// .query(({ input }) => { | ||
// return { | ||
// greeting: `Hello ${input.text}`, | ||
// }; | ||
// }), | ||
|
||
create: publicProcedure | ||
.input(z.object({ name: z.string().min(1) })) | ||
.mutation(async ({ ctx, input }) => { | ||
// simulate a slow db call | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
// create: publicProcedure | ||
// .input(z.object({ name: z.string().min(1) })) | ||
// .mutation(async ({ ctx, input }) => { | ||
// // simulate a slow db call | ||
// await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
await ctx.db.insert(posts).values({ | ||
name: input.name, | ||
}); | ||
}), | ||
// await ctx.db.insert(posts).values({ | ||
// name: input.name, | ||
// }); | ||
// }), | ||
|
||
getLatest: publicProcedure.query(({ ctx }) => { | ||
return ctx.db.query.posts.findFirst({ | ||
orderBy: (posts, { desc }) => [desc(posts.createdAt)], | ||
}); | ||
}), | ||
}); | ||
// getLatest: publicProcedure.query(({ ctx }) => { | ||
// return ctx.db.query.posts.findFirst({ | ||
// orderBy: (posts, { desc }) => [desc(posts.createdAt)], | ||
// }); | ||
// }), | ||
// }); |