From dbd86b5a297535bd8fd2fc2e95dbfec100e4cc2b Mon Sep 17 00:00:00 2001 From: Amagasu Date: Thu, 19 Jun 2025 13:22:58 +0900 Subject: [PATCH] wip AddByRecipeDialog --- frontend/src/components/AddByRecipeDialog.tsx | 72 +++++++++++++++++++ frontend/src/pages/RecipeList.tsx | 22 +++++- 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 frontend/src/components/AddByRecipeDialog.tsx 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}個 +
  • + ))} +
+
+ + {/* レシピを追加する人数分を入力 */} + +
+ 材料を買うものリストに追加します。 +
+
+ + + + +
+ ); +} + +export default AddByRecipeDialog; \ No newline at end of file diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx index 89ec4cc..ccf78cb 100644 --- a/frontend/src/pages/RecipeList.tsx +++ b/frontend/src/pages/RecipeList.tsx @@ -31,6 +31,7 @@ import { 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'; const RecipeList: React.FC = () => { @@ -48,6 +49,10 @@ const RecipeList: React.FC = () => { // すべての料理リスト 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); } @@ -70,6 +75,7 @@ const RecipeList: React.FC = () => { }, []); return ( + <>
@@ -95,8 +101,11 @@ const RecipeList: React.FC = () => { boxShadow: 1, fontSize: '40px' }} - onClick={() => openRecipeById(recipe.recipeId)} - > + onClick = {() => + {setAddByRecipeId(recipe.recipeId) + setOpenAddByRecipeDialog(true)} + } + > {recipe.recipeName} {recipe.maxServings === 0 && { */}
-
+ + + {/* 買うものリストへ追加ダイアログ */} + { + + } + ); };