diff --git a/frontend/src/components/AddByRecipeDialog.tsx b/frontend/src/components/AddByRecipeDialog.tsx new file mode 100644 index 0000000..86c9c6f --- /dev/null +++ b/frontend/src/components/AddByRecipeDialog.tsx @@ -0,0 +1,72 @@ +import React, { useState } from 'react'; +import { + Dialog, + DialogTitle, + DialogContent, + DialogActions, + Button, + Box, +} from '@mui/material'; + +import { recipeApi } from '../services/api'; + +import CloseIcon from '@mui/icons-material/Close'; +import { StuffNameAndAmount } from '../types/types'; + +const AddByRecipeDialog = async ({ + openDialog, + setOpenDialog, + recipeId +}: { + openDialog: boolean, + setOpenDialog: (open: boolean) => void, + recipeId: number, +}) => { + const recipe = await recipeApi.getById(recipeId); + + return ( + setOpenDialog(false)} disableScrollLock={true} PaperProps={{ sx: { minWidth: '300px', maxHeight: '80vh' } }}> + + + 買うものリストへ追加 + setOpenDialog(false)} + sx={{ + cursor: 'pointer', + color: (theme) => theme.palette.grey[500], + }} + /> + + + + レシピ名: {recipe.recipeName} + + + ({recipe.maxservings}) + + + 材料: + + {recipe.stuffNameAndAmountList.map((item, index) => ( + + {item.stuffName} - {item.amount}個 + + ))} + + + + {/* レシピを追加する人数分を入力 */} + + + 材料を買うものリストに追加します。 + + + + + setOpenDialog(false)}>閉じる + + + ); +} + +export default AddByRecipeDialog; \ No newline at end of file diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index a9875d6..47e0a6a 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -193,9 +193,13 @@ const AddRecipe: React.FC = () => { } const cancelNumOfPeopleDialog = async () => { - const recipeId = await handleSaveRecipe(); - if (!recipeId) return false; - setOpenNumOfPeapleDialog(false); + // const allRecipes = await recipeApi.getAllRecipes(); + // const allRecipesId = allRecipes.map(recipe => recipe.recipeId); + // const allStocks = await stockApi.getStocks(); + // const allStuffIdAndAmount = [allStocks.map(stock => stock.stuffId), allStocks.map(stock => stock.amount)]; + // Promise.all(allRecipesId.map(async recipe => { + // (await recipeApi.getById(recipe) + // })) } // コンポーネントマウント時にタスク一覧を取得 diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index e2efffb..24d7039 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -28,10 +28,11 @@ import { } from '@mui/material'; import '../App.css'; import { - Add as AddIcon, Delete as DeleteIcon, ShoppingBasket as ShoppingBasketIcon, - SoupKitchen as SoupKitchenIcon + Add as AddIcon, Delete as DeleteIcon, Edit as EditIcon, ShoppingBasket as ShoppingBasketIcon, + SoupKitchen as SoupKitchenIcon, Close as CloseIcon, TaskAlt as TaskAltIcon } from '@mui/icons-material'; import { ToBuy, Stuff, RecipeWithId, RecipeDetail } from '../types/types'; +import AddByRecipeDialog from '../components/AddByRecipeDialog'; import { useMessage } from '../components/MessageContext'; import { RECIPE_ERRORS } from '../constants/errorMessages'; @@ -41,8 +42,18 @@ const RecipeList: React.FC = () => { const { showErrorMessage } = useMessage(); + const EMPTY_RECIPEWITHID = { + recipeName: '',// レシピ名 + summary: '',// レシピ概要 + recipeId: 0, // レシピID + maxServings: 0 // 最大調理可能数 + } // すべての料理リスト - const [allRecipes, setAllRecipes] = useState(); + const [allRecipes, setAllRecipes] = useState([EMPTY_RECIPEWITHID, EMPTY_RECIPEWITHID]); + + const [openAddByRecipeDialog, setOpenAddByRecipeDialog] = useState(false); + + const [addByRecipeId, setAddByRecipeId] = useState(0); const openRecipeById = (recipeId: number) => { navigate('/addRecipe/' + recipeId); @@ -52,6 +63,8 @@ const RecipeList: React.FC = () => { try { const recipes = await recipeApi.getAllRecipes(); setAllRecipes(recipes); + console.log("マックス"); + console.log(allRecipes.map(recipe => recipe.maxServings)) } catch (error) { showErrorMessage(RECIPE_ERRORS.FETCH_FAILED); // console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); @@ -64,45 +77,72 @@ const RecipeList: React.FC = () => { }, []); return ( - - - - レシピリスト - - - - {/* 料理一覧をマップして各タスクをリストアイテムとして表示 */} - {!allRecipes - ? 読み込み中... - : allRecipes.map((recipe, index) => ( - openRecipeById(recipe.recipeId)} - > - {recipe.recipeName} - - ))} - - - - - navigate('/addRecipe')} className="plusButton"> - - - {/* - 新しいレシピの追加 - */} - + <> + + + + レシピリスト + + + + {/* 料理一覧をマップして各タスクをリストアイテムとして表示 */} + {!allRecipes + ? 読み込み中... + : allRecipes.map((recipe, index) => ( + { + setAddByRecipeId(recipe.recipeId) + setOpenAddByRecipeDialog(true) + } + } + > + {recipe.recipeName} + {recipe.maxServings === 0 ? + + + : + + + {recipe.maxServings}人分 + + - + + { + navigate('/addRecipe/' + recipe.recipeId); + }} + > + + + + + } + + ))} + + + + {/* 買うものリストへ追加ダイアログ */} + {/* + + */} + > ); };
読み込み中...