diff --git a/apps/frontend/src/routes/_app/recipe/.search-food.tsx b/apps/frontend/src/routes/_app/recipe/.search-food.tsx new file mode 100644 index 0000000..709aeaf --- /dev/null +++ b/apps/frontend/src/routes/_app/recipe/.search-food.tsx @@ -0,0 +1,36 @@ +import { IconX } from '@tabler/icons-react' +import type { FC } from 'react' + +type SearchFoodsProps = { + foods: string[] + handleRemoveFoodParam: (food: string) => void +} + +export const SearchFoods: FC = ({ foods, handleRemoveFoodParam }) => ( +
+
+

検索する食材

+

+ {foods.length}品目 +

+
+
+ {foods.map((food) => ( + + ))} +
+
+) diff --git a/apps/frontend/src/routes/_app/recipe/index.tsx b/apps/frontend/src/routes/_app/recipe/index.tsx index 0e2410a..c98b15d 100644 --- a/apps/frontend/src/routes/_app/recipe/index.tsx +++ b/apps/frontend/src/routes/_app/recipe/index.tsx @@ -1,11 +1,12 @@ import { IconLoader2 } from '@tabler/icons-react' import { createFileRoute } from '@tanstack/react-router' -import { useState } from 'react' +import { useCallback, useState } from 'react' import { z } from 'zod' import { LinkButton } from '../../../components/common/LinkButton' import { apiClient } from '../../../lib/apiClient' import { preloadImages } from '../../../utils/imagePreload' import { RecipeCard } from './.recipe-card' +import { SearchFoods } from './.search-food' import { SkeltonCard } from './.skelton-card' const recipeSearchSchema = z.object({ @@ -32,6 +33,7 @@ export const Route = createFileRoute('/_app/recipe/')({ }) const Recipe = () => { + const navigate = Route.useNavigate() const { foods } = Route.useSearch() const { data, page } = Route.useLoaderData() const [recipes, setRecipes] = useState(data) @@ -56,12 +58,22 @@ const Recipe = () => { setIsLoading(false) } + const handleRemoveFoodParam = useCallback( + (food: string) => { + if (foods.length <= 1) return + const newFoods = foods.filter((f) => f !== food) + navigate({ to: '/recipe', search: { foods: newFoods } }) + }, + [foods, navigate], + ) + return ( <>

レシピ一覧

Recipe

+
{recipes.map((recipe) => ( @@ -85,20 +97,35 @@ const Recipe = () => { ) } -const PendingRecipe = () => ( - <> -
-

レシピ一覧

-

Recipe

-
-
- {[...Array(5)].map((_, i) => ( - // biome-ignore lint/suspicious/noArrayIndexKey: This is a skeleton component, so index key is not a problem - - ))} -
- -) +const PendingRecipe = () => { + const { foods } = Route.useSearch() + const navigate = Route.useNavigate() + + const handleRemoveFoodParam = useCallback( + (food: string) => { + if (foods.length <= 1) return + const newFoods = foods.filter((f) => f !== food) + navigate({ to: '/recipe', search: { foods: newFoods } }) + }, + [foods, navigate], + ) + + return ( + <> +
+

レシピ一覧

+

Recipe

+
+ +
+ {[...Array(5)].map((_, i) => ( + // biome-ignore lint/suspicious/noArrayIndexKey: This is a skeleton component, so index key is not a problem + + ))} +
+ + ) +} const ErrorComponent = () => ( <>