import React, { useState } from 'react'; import { useAppData } from '../context/AppDataContext'; import { useNavigate } from 'react-router-dom'; import { generateProfile } from '../utils/calculations'; import './Settings.css'; const Settings: React.FC = () => { const { profile, saveProfile, clearData } = useAppData(); const navigate = useNavigate(); if (!profile) return null; const [weight, setWeight] = useState(profile.weight.toString()); const [activity, setActivity] = useState(profile.activityLevel); const [goal, setGoal] = useState(profile.goal); const handleUpdate = () => { if (window.confirm('更新體重/活動量會重新計算您的 TDEE 與每日營養目標,確定要更新嗎?')) { const newProfile = generateProfile( profile.height, Number(weight), profile.age, profile.gender, activity, goal ); saveProfile(newProfile); alert('已更新您的營養目標!'); } }; const handleReset = () => { if (window.confirm('確定要清除所有資料嗎?這將會刪除您的個人檔案與所有歷史紀錄。')) { clearData(); navigate('/onboarding'); } }; return (

設定

個人狀態更新

當前目標:{profile.targetCalories} kcal / 飲水:{profile.targetWater} ml

setWeight(e.target.value)} />

危險區域

); }; export default Settings;