diff --git a/backend/src/main/java/com/example/todoapp/config/InitTables.java b/backend/src/main/java/com/example/todoapp/config/InitTables.java index e55565e..642fe97 100644 --- a/backend/src/main/java/com/example/todoapp/config/InitTables.java +++ b/backend/src/main/java/com/example/todoapp/config/InitTables.java @@ -43,11 +43,11 @@ public class InitTables { @PostConstruct public void initTables() { - tobuysRepository.deleteAll(); //データを残す場合はコメントアウト - stocksRepository.deleteAll(); //データを残す場合はコメントアウト - recipeStuffsRepository.deleteAll(); //データを残す場合はコメントアウト - recipesRepository.deleteAll(); //データを残す場合はコメントアウト - stuffsRepository.deleteAll(); //データを残す場合はコメントアウト + // tobuysRepository.deleteAll(); //データを残す場合はコメントアウト + // stocksRepository.deleteAll(); //データを残す場合はコメントアウト + // recipeStuffsRepository.deleteAll(); //データを残す場合はコメントアウト + // recipesRepository.deleteAll(); //データを残す場合はコメントアウト + // stuffsRepository.deleteAll(); //データを残す場合はコメントアウト if (stuffsRepository.count() > 0) { // すでにデータが存在する場合は何もしない diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 3750af9..463f439 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -13,7 +13,7 @@ import StockPage from './pages/StockPage'; import './App.css'; // 必要なインポートを追加 import AddRecipe from './pages/AddRecipe'; -import DishList from './pages/DishList'; +import RecipeList from './pages/RecipeList'; //カレンダーライブラリ import FullCalendar from '@fullcalendar/react'; import dayGridPlugin from "@fullcalendar/daygrid"; @@ -110,10 +110,10 @@ const App: React.FC = () => { /> {/* 料理リストへのルートを追加 */} - + } /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index 8aeda09..b5f59be 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -112,8 +112,8 @@ const Layout: React.FC = () => { handleNavigate('/dishList')} - selected={isSelected('/dishList')} + onClick={() => handleNavigate('/recipeList')} + selected={isSelected('/recipeList')} > diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index 64a36ca..fb2238e 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -68,7 +68,6 @@ const AddRecipe: React.FC = () => { setItems(recipe.stuffAndAmountArray) } } - loadRecipe(); const handleSaveRecipe = async () => { @@ -93,17 +92,23 @@ const AddRecipe: React.FC = () => { } const handleSubmit = async () => { - const recipeId = await handleSaveRecipe() - alert('レシピが保存されました!') // 仮メッセージ - // navigate('/tasks'); + const recipeId = await handleSaveRecipe(); + // alert('レシピが保存されました!'); + navigate('/recipeList'); } const handleSubmitAndAddToBuy = async () => { const recipeId = await handleSaveRecipe(); - await toBuyApi.addByRecipe(recipeId) - navigate('/tasks') + await toBuyApi.addByRecipe(recipeId); + // alert('レシピが保存されて買うものリストに追加されました!'); + navigate('/tasks'); } + // コンポーネントマウント時にタスク一覧を取得 + useEffect(() => { + loadRecipe(); + }, []); + return ( (recipeId && !recipeName) ?

読み込み中...

@@ -117,11 +122,13 @@ const AddRecipe: React.FC = () => { setRecipeName(e.target.value)} /> - setRecipeSummary(e.target.value)} /> -

材料リスト

+

+ 材料リスト +

{/* すべての材料情報を表示 */} {(!items || !items.length) ? (

+ボタンで材料を追加してください

) diff --git a/frontend/src/pages/RecipeList.tsx b/frontend/src/pages/RecipeList.tsx new file mode 100644 index 0000000..42826db --- /dev/null +++ b/frontend/src/pages/RecipeList.tsx @@ -0,0 +1,113 @@ +import React, { useState, useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { recipeApi } from '../services/api'; +import { + Container, + Typography, + Tooltip, + List, + ListItem, + ListItemText, + ListItemSecondaryAction, + IconButton, + Checkbox, + Fab, + Dialog, + DialogTitle, + DialogContent, + DialogActions, + TextField, + Button, + Box, + FormControlLabel, + FormGroup, + MenuItem, + Select, + FormControl, + InputLabel +} from '@mui/material'; +import { + Add as AddIcon, Delete as DeleteIcon, ShoppingBasket as ShoppingBasketIcon, + SoupKitchen as SoupKitchenIcon +} from '@mui/icons-material'; +import { ToBuy, Stuff, RecipeWithId, RecipeDetail } from '../types/types'; + +const RecipeList: React.FC = () => { + const navigate = useNavigate(); + // 料理リストの料理名を格納する配列 + + // すべての料理リスト + const [allRecipes, setAllRecipes] = useState(); + + const openRecipeById = (recipeId: number) => { + navigate('/addRecipe/' + recipeId); + } + + const fetchAllRecipes = async () => { + try { + const recipes = await recipeApi.getAllRecipes(); + setAllRecipes(recipes); + } catch (error) { + alert("レシピの取得に失敗しました."); + // console.error(`${TASK_ERRORS.FETCH_FAILED}:`, error); + } + }; + + // コンポーネントマウント時にタスク一覧を取得 + useEffect(() => { + fetchAllRecipes(); + }, []); + + return ( + + +
+

料理リスト

+
+
+ {/* */} + {/* 料理一覧をマップして各タスクをリストアイテムとして表示 */} + {!allRecipes + ?

読み込み中...

+ : allRecipes.map((recipe, index) => ( + + + + // + ))} + {/*
*/} +
+
+ +
+
+ +
+ ); +}; + +export default RecipeList; \ No newline at end of file diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index a1d23f2..39d675a 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -25,6 +25,7 @@ import { TOBUY_ERRORS } from '../constants/errorMessages'; import EditAmountDialog from '../components/EditAmountDialog'; import AddStuffAmountDialog from '../components/AddStuffAmountDialog'; import BuyDialog from '../components/BuyDialog'; +import { useNavigate } from 'react-router-dom'; //import { FaCarrot } from "react-icons/fa6"; //エラー起きる いったん保留 @@ -39,6 +40,9 @@ const EMPTY_TOBUY: NewToBuy = { } const TaskListPage: React.FC = () => { + + const navigate = useNavigate(); + // タスク一覧の状態管理 const [tobuys, setToBuys] = useState([]); @@ -289,8 +293,8 @@ const TaskListPage: React.FC = () => { color="primary" sx={{ position: 'fixed', bottom: 16, left: '60%', transform: 'translateX(-50%)' }} onClick={() => { - setOpenAddToBuyDialog(true); - //handleNavigate('/AddDishies1'); + // setOpenAddToBuyDialog(true); + navigate('/RecipeList'); }} //selected={isSelected('/test')} > diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index 0187ecd..7a5a4a2 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -3,7 +3,7 @@ * バックエンドAPIとの通信を担当するモジュール * 認証、タスク管理などの機能を提供 */ -import { LoginCredentials, RegisterCredentials, AuthResponse, /* Task, */ ToBuy, Stuff, Stock, RecipeData, StuffAndCategoryAndAmount } from '../types/types'; +import { LoginCredentials, RegisterCredentials, AuthResponse, /* Task, */ ToBuy, Stuff, Stock, RecipeDetail, StuffAndCategoryAndAmount, RecipeWithId } from '../types/types'; import { AUTH_ERRORS, TOBUY_ERRORS, STOCK_ERRORS, RECIPE_ERRORS } from '../constants/errorMessages'; // APIのベースURL - 環境変数から取得するか、デフォルト値を使用 @@ -343,7 +343,7 @@ export const recipeApi = { * @param recipeData レシピデータ(名前、説明、材料リスト) * @returns レシピ追加レスポンス(内联类型) */ - addRecipe: async (recipeData: RecipeData): Promise<{ + addRecipe: async (recipeData: RecipeDetail): Promise<{ result: string; recipeId: number; message: string; @@ -370,7 +370,7 @@ export const recipeApi = { * @param recipeData 更新するレシピ情報 * @returns 更新結果(成功/失敗) */ - updateRecipe: async (recipeData: { recipeId: number } & RecipeData): Promise<{ result: boolean; message: string }> => { + updateRecipe: async (recipeData: { recipeId: number } & RecipeDetail): Promise<{ result: boolean; message: string }> => { // console.log('recipeData:', recipeData) const response = await fetch(`${API_BASE_URL}/api/recipes/update`, { @@ -392,11 +392,7 @@ export const recipeApi = { * 全レシピを取得 * @returns レシピ一覧 */ - getAllRecipes: async (): Promise> => { + getAllRecipes: async (): Promise => { const response = await fetch(`${API_BASE_URL}/api/recipes/getAll`, { method: 'GET', headers: getHeaders(), // 認証トークンを含むヘッダー diff --git a/frontend/src/types/types.ts b/frontend/src/types/types.ts index 190c1f7..4c81793 100644 --- a/frontend/src/types/types.ts +++ b/frontend/src/types/types.ts @@ -119,13 +119,20 @@ export interface RegisterCredentials { password: string; // パスワード } +export interface Recipe { + recipeName: string;// レシピ名 + summary: string;// レシピ概要 +} + +export interface RecipeWithId extends Recipe { + recipeId: number; +} + /** * レシピ登録用の複合型定義 * レシピ基本情報と材料リストを統合 */ -export interface RecipeData { - recipeName: string;// レシピ名 - summary: string;// レシピ概要 +export interface RecipeDetail extends Recipe { // 材料リスト(直接配列として内包) stuffAndAmountArray: {