Skip to content

Commit 6a0bf3c

Browse files
committed
refactor: use generated type
1 parent 2c578e6 commit 6a0bf3c

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

app/routes/_index.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import { parseWithZod } from "@conform-to/zod";
22
import { Anchor, Card, Container, Divider, Group, Stack } from "@mantine/core";
3-
import type {
4-
ActionFunctionArgs,
5-
LinksFunction,
6-
LoaderFunctionArgs,
7-
MetaFunction,
8-
} from "react-router";
9-
import {
10-
data,
11-
Link,
12-
redirect,
13-
useActionData,
14-
useLoaderData,
15-
useNavigation,
16-
} from "react-router";
3+
import { data, Link, redirect, useNavigation } from "react-router";
174
import { getQuery, withQuery } from "ufo";
185

196
import Fa6SolidMagnifyingGlass from "~icons/fa6-solid/magnifying-glass";
@@ -27,8 +14,9 @@ import {
2714
searchApiV1DataSearchGet,
2815
} from "../generated/api/client";
2916
import type { SearchedNote, Topic } from "../generated/api/schemas";
17+
import type { Route } from "./+types/_index";
3018

31-
export const meta: MetaFunction = () => {
19+
export const meta: Route.MetaFunction = () => {
3220
return [
3321
{ title: "BirdXplorer" },
3422
{
@@ -43,7 +31,7 @@ export const meta: MetaFunction = () => {
4331
];
4432
};
4533

46-
export const links: LinksFunction = () => {
34+
export const links: Route.LinksFunction = () => {
4735
return [
4836
{
4937
rel: "canonical",
@@ -52,7 +40,7 @@ export const links: LinksFunction = () => {
5240
];
5341
};
5442

55-
export const loader = async (args: LoaderFunctionArgs) => {
43+
export const loader = async (args: Route.LoaderArgs) => {
5644
const rawSearchParams = getQuery(args.request.url);
5745
const searchQuery =
5846
await noteSearchParamSchema.safeParseAsync(rawSearchParams);
@@ -96,9 +84,10 @@ export const loader = async (args: LoaderFunctionArgs) => {
9684
};
9785
};
9886

99-
export default function Index() {
100-
const loaderData = useLoaderData<typeof loader>();
101-
const lastResult = useActionData<typeof action>();
87+
export default function Index({
88+
actionData,
89+
loaderData,
90+
}: Route.ComponentProps) {
10291
const isLoadingSearchResults = useNavigation().state !== "idle";
10392

10493
const {
@@ -121,7 +110,7 @@ export default function Index() {
121110
<h2 className="sr-only">コミュニティノートを検索する</h2>
122111
<SearchForm
123112
defaultValue={searchQuery ?? undefined}
124-
lastResult={lastResult}
113+
lastResult={actionData}
125114
topics={
126115
// react-router の型がうまく機能せず topics が unknown になったため
127116
topics as Topic[]
@@ -203,7 +192,7 @@ export default function Index() {
203192
);
204193
}
205194

206-
export const action = async ({ request }: ActionFunctionArgs) => {
195+
export const action = async ({ request }: Route.ActionArgs) => {
207196
const formData = await request.formData();
208197
const submission = parseWithZod(formData, {
209198
schema: noteSearchParamSchema,

0 commit comments

Comments
 (0)