Skip to content

Commit

Permalink
create a todopage now based on date in url
Browse files Browse the repository at this point in the history
  • Loading branch information
SeansC12 committed Dec 10, 2024
1 parent 7a067d4 commit 59db4c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions app/models/todo.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -39,12 +39,14 @@ export function getTodoPageListItems({
export function createTodoPage({
title,
userId,
}: Pick<TodoPage, "title"> & {
createdAt,
}: Pick<TodoPage, "title" | "createdAt"> & {
userId: User["id"];
}) {
return prisma.todoPage.create({
data: {
title,
createdAt,
user: {
connect: {
id: userId,
Expand Down
9 changes: 6 additions & 3 deletions app/routes/_todos.$date.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions app/routes/_todos.$date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 59db4c2

Please sign in to comment.