From 50813ac9eb1d35fe83d92597dca38c618a90b207 Mon Sep 17 00:00:00 2001 From: "Masaharu.Kato" Date: Thu, 5 Jun 2025 15:56:57 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9D=90=E6=96=99=E3=81=AE=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/StuffNameDropDown.tsx | 16 ---- frontend/src/pages/TaskListPage.tsx | 85 ++++++++++++++----- frontend/src/services/api.ts | 2 +- 3 files changed, 65 insertions(+), 38 deletions(-) delete mode 100644 frontend/src/components/StuffNameDropDown.tsx diff --git a/frontend/src/components/StuffNameDropDown.tsx b/frontend/src/components/StuffNameDropDown.tsx deleted file mode 100644 index 32b613a..0000000 --- a/frontend/src/components/StuffNameDropDown.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from "react"; -import { toBuyApi } from '../services/api'; -import { FormControl, InputLabel, Select, MenuItem } from "@mui/material"; - -const StuffNameDropDown = ({ value, onChange }) => { - return ( - - 材料を選択 - - - ); -}; - -export default StuffNameDropDown; \ No newline at end of file diff --git a/frontend/src/pages/TaskListPage.tsx b/frontend/src/pages/TaskListPage.tsx index d5d6aab..e44bc7b 100644 --- a/frontend/src/pages/TaskListPage.tsx +++ b/frontend/src/pages/TaskListPage.tsx @@ -3,7 +3,7 @@ * タスクの表示、作成、完了状態の切り替え、削除などの機能を提供 */ import React, { useState, useEffect } from 'react'; -import { toBuyApi } from '../services/api'; +import { toBuyApi, stuffApi } from '../services/api'; import { Container, Typography, @@ -23,13 +23,17 @@ import { Button, Box, FormControlLabel, - FormGroup + FormGroup, + FormControl, + InputLabel, + Select, + MenuItem } from '@mui/material'; import { Add as AddIcon, Delete as DeleteIcon, ShoppingBasket as ShoppingBasketIcon, SoupKitchen as SoupKitchenIcon } from '@mui/icons-material'; -import { Task, ToBuy } from '../types/types'; +import { Task, ToBuy, Stuff } from '../types/types'; import { TASK_ERRORS } from '../constants/errorMessages'; //import { FaCarrot } from "react-icons/fa6"; //エラー起きる いったん保留 import CategoryDropDown from "../components/CategoryDropDown"; @@ -38,8 +42,8 @@ import CategoryDropDown from "../components/CategoryDropDown"; // 新規タスクの初期状態 -const EMPTY_TASK: Omit & {category: string} & {newAddition: boolean} = { - stuff_id: 0, +const EMPTY_TASK: Omit & { stuff_id: number | null, category: string } & { newAddition: boolean } = { + stuff_id: null, stuff_name: '', amount: 0, shop: '', @@ -55,12 +59,15 @@ const TaskListPage: React.FC = () => { //在庫登録ダイアログの表示状態 const [openInfoDialog, setOpenInfoDialog] = useState(false); - + const [selectedTask, setSelectedTask] = useState(); const [newToBuy, setNewToBuy] = useState(EMPTY_TASK); + const [stuffs, setStuffs] = useState([]); + + // コンポーネントマウント時にタスク一覧を取得 useEffect(() => { fetchTasks(); @@ -79,6 +86,12 @@ const TaskListPage: React.FC = () => { } }; + const onChangeCategory = async (category: string) => { + setNewToBuy({ ...newToBuy, category }) + const result = await stuffApi.getStuffs(category) + setStuffs(result.stuff_array) + } + // /** // * タスクの完了状態を切り替えるハンドラー // * 対象タスクの完了状態を反転させてAPIに更新を要求 @@ -222,23 +235,53 @@ const TaskListPage: React.FC = () => { {/* 新規タスク作成ダイアログ */} setOpenDialog(false)} disableScrollLock={true}> - - 材料の追加 - - } - label="食材を新規追加" - checked={newToBuy.newAddition} - onChange={(e) => setNewToBuy({ ...newToBuy, newAddition:(e.target as HTMLInputElement).checked })} - /> - + + 材料の追加 + + } + label="食材を新規追加" + checked={newToBuy.newAddition} + onChange={(e) => setNewToBuy({ ...newToBuy, newAddition: (e.target as HTMLInputElement).checked })} + /> + {/*材料カテゴリ選択 */} - + + + カテゴリ + + + + {!newToBuy.newAddition && + 材料名(選択) + + } + {/* タスクタイトル入力フィールド */} - { value={newToBuy.stuff_name} onChange={(e) => setNewToBuy({ ...newToBuy, stuff_name: e.target.value })} sx={{ marginBottom: 2 }} - /> + />} {/* 数量入力フィールド */} { handleDeleteTask(selectedTask.tobuy_id) setOpenInfoDialog(false) } - }} + }} variant="contained"> 登録 - + ); }; diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index aa0a620..a77a601 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -128,7 +128,7 @@ export const toBuyApi = { * @param tobuy 作成する材料情報 * @returns 作成された材料情報 */ - addToBuy: async (tobuy: Omit & { category: string }): Promise => { + addToBuy: async (tobuy: Omit & { stuff_id: number | null, category: string }): Promise => { // const response = await fetch(`${API_BASE_URL}/api/tasks`, { // method: 'POST', // headers: getHeaders(),