diff --git a/app/models/todo.server.ts b/app/models/todo.server.ts index 1d5b3c0..89f412c 100644 --- a/app/models/todo.server.ts +++ b/app/models/todo.server.ts @@ -21,12 +21,12 @@ export function getTodoPageListItems({ userId: User["id"]; date: Date; }) { - console.log(date); + console.log("prisma date", date); // return the todo pages for the day of the given date return prisma.todoPage.findMany({ where: { userId, - updatedAt: { + createdAt: { gte: date, lt: new Date(date.getTime() + 1000 * 60 * 60 * 24), }, @@ -39,12 +39,14 @@ export function getTodoPageListItems({ export function createTodoPage({ title, userId, -}: Pick & { + createdAt, +}: Pick & { userId: User["id"]; }) { return prisma.todoPage.create({ data: { title, + createdAt, user: { connect: { id: userId, diff --git a/app/routes/_todos.$date.new.tsx b/app/routes/_todos.$date.new.tsx index 6416374..c5722e3 100644 --- a/app/routes/_todos.$date.new.tsx +++ b/app/routes/_todos.$date.new.tsx @@ -18,9 +18,10 @@ import { validateTodoPageName } from "~/utils"; import InputErrorText from "~/components/InputErrorText"; -export const action = async ({ request }: ActionFunctionArgs) => { +export const action = async ({ params, request }: ActionFunctionArgs) => { const userId = await requireUserId(request); const todayDate = new Date().toISOString().split("T")[0]; + const createdAt = params.date ? new Date(params.date) : new Date(); const formData = await request.formData(); const title = formData.get("title") as string; @@ -30,10 +31,12 @@ export const action = async ({ request }: ActionFunctionArgs) => { return json({ todoPageNameError: message }, { status: 400 }); } - const todoPage = await createTodoPage({ title, userId }); + console.log("new action", createdAt.toISOString()); + + const todoPage = await createTodoPage({ title, userId, createdAt }); console.log("date", todayDate); - return redirect(`/${todayDate}/${todoPage.id}`); + return redirect(`/${createdAt.toISOString().split("T")[0]}/${todoPage.id}`); }; export default function NewTodoPage() { diff --git a/app/routes/_todos.$date.tsx b/app/routes/_todos.$date.tsx index cbc3eaa..8142b1e 100644 --- a/app/routes/_todos.$date.tsx +++ b/app/routes/_todos.$date.tsx @@ -35,8 +35,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { const todoPageListItems = await getTodoPageListItems({ userId, date: date }); - console.log(todoPageListItems); - if (todoPageListItems) { } return json({ todoPageListItems: todoPageListItems, dateInUrl: date });