-
Notifications
You must be signed in to change notification settings - Fork 0
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
b0f30fc
commit 99ad80e
Showing
13 changed files
with
254 additions
and
124 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- CreateTable | ||
CREATE TABLE "Todo" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"title" TEXT NOT NULL, | ||
"complete" BOOLEAN NOT NULL, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL | ||
); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "sqlite" |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Todo { | ||
id String @id @default(uuid()) | ||
title String | ||
complete Boolean | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client" | ||
|
||
type TodoItemProps = { | ||
id: string | ||
title: string | ||
complete: boolean | ||
toggleTodo: (id: string, complete: boolean) => void | ||
} | ||
|
||
export function TodoItem({ id, title, complete, toggleTodo }: TodoItemProps) { | ||
return ( | ||
<li className="flex gap-1 items-center"> | ||
<input | ||
id={id} | ||
type="checkbox" | ||
className="cursor-pointer peer" | ||
defaultChecked={complete} | ||
onChange={e => toggleTodo(id, e.target.checked)} | ||
/> | ||
<label | ||
htmlFor={id} | ||
className="cursor-pointer peer-checked:line-through peer-checked:text-slate-500" | ||
> | ||
{title} | ||
</label> | ||
</li> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
|
||
const globalForPrisma = globalThis as unknown as { | ||
prisma: PrismaClient | undefined | ||
} | ||
|
||
export const prisma = globalForPrisma.prisma ?? new PrismaClient() | ||
|
||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma |
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
import { redirect } from "next/navigation" | ||
import Link from "next/link" | ||
import { prisma } from "../db" | ||
|
||
async function createTodo(data: FormData) { | ||
"use server" | ||
|
||
const title = data.get("title")?.valueOf() | ||
if (typeof title !== "string" || title.length === 0) { | ||
throw new Error("Invalid Title") | ||
} | ||
|
||
await prisma.todo.create({ data: { title, complete: false } }) | ||
redirect("/") | ||
} | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<header className="flex justify-between items-center mb-4"> | ||
<h1 className="text-2xl">New</h1> | ||
</header> | ||
<form action={createTodo} className="flex gap-2 flex-col"> | ||
<input | ||
type="text" | ||
name="title" | ||
className="border border-slate-300 bg-transparent rounded px-2 py-1 outline-none focus-within:border-slate-100" | ||
/> | ||
<div className="flex gap-1 justify-end"> | ||
<Link | ||
href=".." | ||
className="border border-slate-300 text-slate-300 px-2 py-1 rounded hover:bg-slate-700 focus-within:bg-slate-700 outline-none" | ||
> | ||
Cancel | ||
</Link> | ||
<button | ||
type="submit" | ||
className="border border-slate-300 text-slate-300 px-2 py-1 rounded hover:bg-slate-700 focus-within:bg-slate-700 outline-none" | ||
> | ||
Create | ||
</button> | ||
</div> | ||
</form> | ||
</> | ||
) | ||
} |
Oops, something went wrong.