Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFetcherだとValidationがうまく聞いていなかったのを修正 #190

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions web/app/routes/$userName+/page+/$slug+/edit/_edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFormProps, getTextareaProps, useForm } from "@conform-to/react";
import { getZodConstraint, parseWithZod } from "@conform-to/zod";
import type { ActionFunction, LoaderFunction } from "@remix-run/node";
import { useActionData, useLoaderData } from "@remix-run/react";
import { useLoaderData } from "@remix-run/react";
import { useFetcher } from "@remix-run/react";
import { z } from "zod";
import { authenticator } from "~/utils/auth.server";
Expand Down Expand Up @@ -97,11 +97,10 @@ export const action: ActionFunction = async ({ request, params }) => {

export default function EditPage() {
const { currentUser, page } = useLoaderData<typeof loader>();
const actionData = useActionData<typeof action>();
const fetcher = useFetcher();
const fetcher = useFetcher<typeof action>();
const [form, { title, pageContent }] = useForm({
id: "edit-page",
lastResult: actionData?.lastResult,
lastResult: fetcher.data?.lastResult,
constraint: getZodConstraint(schema),
shouldValidate: "onBlur",
shouldRevalidate: "onInput",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ export function EditHeader({
return (
<header className="mb-10 z-10 ">
<div className="max-w-7xl mx-auto py-4 px-4 sm:px-6 flex justify-between items-center">
<Button variant="ghost">
<Link
to={
pageSlug
? `/${currentUser?.userName}/page/${pageSlug}`
: `/${currentUser?.userName}`
}
className="text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-white"
>
<Link
to={
pageSlug
? `/${currentUser?.userName}/page/${pageSlug}`
: `/${currentUser?.userName}`
}
className="text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-white"
>
<Button variant="ghost">
{isLoading ? (
<Loader2 className="w-6 h-6 animate-spin" />
) : (
<ArrowLeft className="w-6 h-6" />
)}
</Link>
</Button>
</Button>
</Link>
<Button type="submit" variant="ghost" disabled={isSubmitting}>
{isSubmitting ? (
<>
Expand Down
Loading