Skip to content

Commit e06e003

Browse files
committed
remove use of SerializeFrom
1 parent 0f380b5 commit e06e003

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

app/routes/settings+/profile.connections.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ export async function loader({ request }: Route.LoaderArgs) {
8484
)
8585
}
8686

87-
export function headers({ loaderHeaders }: Route.HeadersArgs) {
87+
export const headers = (({ loaderHeaders }) => {
8888
const headers = {
8989
'Server-Timing': loaderHeaders.get('Server-Timing') ?? '',
9090
}
9191
return headers
92-
}
92+
}) satisfies Route.HeadersFunction
9393

9494
export async function action({ request }: Route.ActionArgs) {
9595
const userId = await requireUserId(request)

app/routes/users+/$username_+/__note-editor.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import {
88
type FieldMetadata,
99
} from '@conform-to/react'
1010
import { getZodConstraint, parseWithZod } from '@conform-to/zod'
11-
import { type Note, type NoteImage } from '@prisma/client'
1211
import { useState } from 'react'
13-
import { Form, useActionData, type useLoaderData } from 'react-router'
12+
import { Form } from 'react-router'
1413
import { z } from 'zod'
1514
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
1615
import { floatingToolbarClassName } from '#app/components/floating-toolbar.tsx'
@@ -21,7 +20,7 @@ import { Label } from '#app/components/ui/label.tsx'
2120
import { StatusButton } from '#app/components/ui/status-button.tsx'
2221
import { Textarea } from '#app/components/ui/textarea.tsx'
2322
import { cn, getNoteImgSrc, useIsPending } from '#app/utils/misc.tsx'
24-
import { type action } from './__note-editor.server'
23+
import { type Info } from './+types/notes.$noteId_.edit.ts'
2524

2625
const titleMinLength = 1
2726
const titleMaxLength = 100
@@ -43,8 +42,6 @@ const ImageFieldsetSchema = z.object({
4342

4443
export type ImageFieldset = z.infer<typeof ImageFieldsetSchema>
4544

46-
type SerializeFrom<T> = ReturnType<typeof useLoaderData<T>>
47-
4845
export const NoteEditorSchema = z.object({
4946
id: z.string().optional(),
5047
title: z.string().min(titleMinLength).max(titleMaxLength),
@@ -54,14 +51,11 @@ export const NoteEditorSchema = z.object({
5451

5552
export function NoteEditor({
5653
note,
54+
actionData,
5755
}: {
58-
note?: SerializeFrom<
59-
Pick<Note, 'id' | 'title' | 'content'> & {
60-
images: Array<Pick<NoteImage, 'id' | 'altText'>>
61-
}
62-
>
56+
note?: Info['loaderData']['note']
57+
actionData?: Info['actionData']
6358
}) {
64-
const actionData = useActionData<typeof action>()
6559
const isPending = useIsPending()
6660

6761
const [form, fields] = useForm({

app/routes/users+/$username_+/notes.$noteId_.edit.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { invariantResponse } from '@epic-web/invariant'
2-
import { type LoaderFunctionArgs, useLoaderData } from 'react-router'
32
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
43
import { requireUserId } from '#app/utils/auth.server.ts'
54
import { prisma } from '#app/utils/db.server.ts'
5+
import { type Route } from './+types/notes.$noteId_.edit.ts'
66
import { NoteEditor } from './__note-editor.tsx'
77

88
export { action } from './__note-editor.server.tsx'
99

10-
export async function loader({ params, request }: LoaderFunctionArgs) {
10+
export async function loader({ params, request }: Route.LoaderArgs) {
1111
const userId = await requireUserId(request)
1212
const note = await prisma.note.findFirst({
1313
select: {
@@ -27,13 +27,14 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
2727
},
2828
})
2929
invariantResponse(note, 'Not found', { status: 404 })
30-
return { note: note }
30+
return { note }
3131
}
3232

33-
export default function NoteEdit() {
34-
const data = useLoaderData<typeof loader>()
35-
36-
return <NoteEditor note={data.note} />
33+
export default function NoteEdit({
34+
loaderData,
35+
actionData,
36+
}: Route.ComponentProps) {
37+
return <NoteEditor note={loaderData.note} actionData={actionData} />
3738
}
3839

3940
export function ErrorBoundary() {

0 commit comments

Comments
 (0)