import type { ActionArgs, LoaderArgs } from '@remix-run/node' import { json, redirect } from '@remix-run/node' import { Form, useCatch, useLoaderData } from '@remix-run/react' import invariant from 'tiny-invariant' import { deleteNote, getNote } from '~/models/note.server' import { requireUserId } from '~/session.server' export async function loader({ request, params }: LoaderArgs) { const userId = await requireUserId(request) invariant(params.noteId, 'noteId not found') const note = await getNote({ userId, id: params.timeEntryId }) if (!note) { throw new Response('Not Found', { status: 404 }) } return json({ note }) } export async function action({ request, params }: ActionArgs) { const userId = await requireUserId(request) invariant(params.timeEntryId, 'timeEntryId not found') await deleteNote({ userId, id: params.timeEntryId }) return redirect('/notes') } export default function NoteDetailsPage() { const data = useLoaderData() return (

{data.note.title}

{data.note.body}


) } export function ErrorBoundary({ error }: { error: Error }) { console.error(error) return
An unexpected error occurred: {error.message}
} export function CatchBoundary() { const caught = useCatch() if (caught.status === 404) { return
Note not found
} throw new Error(`Unexpected caught response with status: ${caught.status}`) }