health-assistant / frontend /src /pages /ExerciseTracker.jsx
yuting111222's picture
Add Health Assistant AI project with AI food analyzer and complete backend/frontend
89b8989
import React from 'react';
import { useState } from 'react';
import { PlusIcon } from '@heroicons/react/24/outline';
const exerciseTypes = [
{ id: 'walking', name: 'ζ­₯葌', caloriesPerMinute: 4 },
{ id: 'running', name: 'θ·‘ζ­₯', caloriesPerMinute: 10 },
{ id: 'cycling', name: '騎θ‡ͺ葌車', caloriesPerMinute: 7 },
{ id: 'swimming', name: 'ζΈΈζ³³', caloriesPerMinute: 8 },
{ id: 'yoga', name: 'η‘œδΌ½', caloriesPerMinute: 3 },
{ id: 'weightlifting', name: '重訓', caloriesPerMinute: 6 },
];
export default function ExerciseTracker() {
const [selectedExercise, setSelectedExercise] = useState('');
const [duration, setDuration] = useState('');
const calculateCalories = () => {
const exercise = exerciseTypes.find(e => e.id === selectedExercise);
if (exercise && duration) {
return exercise.caloriesPerMinute * parseInt(duration);
}
return 0;
};
return (
<div className="space-y-6">
<div className="bg-white p-6 rounded-lg shadow">
<h2 className="text-2xl font-semibold text-gray-800 mb-6">θ¨˜ιŒ„ι‹ε‹•</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-4">
<div>
<label htmlFor="exercise-type" className="block text-sm font-medium text-gray-700">
ι‹ε‹•ι‘žεž‹
</label>
<select
id="exercise-type"
value={selectedExercise}
onChange={(e) => setSelectedExercise(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>
<option value="">ιΈζ“‡ι‹ε‹•ι‘žεž‹</option>
{exerciseTypes.map(type => (
<option key={type.id} value={type.id}>{type.name}</option>
))}
</select>
</div>
<div>
<label htmlFor="duration" className="block text-sm font-medium text-gray-700">
運動時間 (εˆ†ι˜)
</label>
<input
type="number"
id="duration"
value={duration}
onChange={(e) => setDuration(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
placeholder="0"
min="0"
/>
</div>
{selectedExercise && duration && (
<div className="p-4 bg-green-50 rounded-md">
<p className="text-green-700">ι θ¨ˆζΆˆθ€—ε‘θ·―ι‡Œ: {calculateCalories()} kcal</p>
</div>
)}
<button
type="button"
className="w-full flex justify-center items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700"
>
<PlusIcon className="h-5 w-5 mr-2" />
ζ–°ε’žθ¨˜ιŒ„
</button>
</div>
<div className="bg-gray-50 p-4 rounded-lg">
<h3 className="text-lg font-medium text-gray-900 mb-4">ζœ¬ι€±ι‹ε‹•η΅±θ¨ˆ</h3>
<div className="space-y-4">
<div>
<div className="flex justify-between text-sm text-gray-600">
<span>總運動時間</span>
<span>180 εˆ†ι˜</span>
</div>
<div className="w-full bg-gray-200 rounded-full h-2.5 mt-2">
<div className="bg-indigo-600 h-2.5 rounded-full" style={{ width: '60%' }}></div>
</div>
</div>
<div>
<div className="flex justify-between text-sm text-gray-600">
<span>ζΆˆθ€—ε‘θ·―ι‡Œ</span>
<span>1,200 kcal</span>
</div>
<div className="w-full bg-gray-200 rounded-full h-2.5 mt-2">
<div className="bg-green-600 h-2.5 rounded-full" style={{ width: '40%' }}></div>
</div>
</div>
</div>
</div>
</div>
</div>
{/* ι‹ε‹•θ¨˜ιŒ„ */}
<div className="bg-white p-6 rounded-lg shadow">
<h3 className="text-xl font-semibold text-gray-800 mb-4">ζœ€θΏ‘ηš„ι‹ε‹•θ¨˜ιŒ„</h3>
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ζ—₯期</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ι‹ε‹•ι‘žεž‹</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ζ™‚ι–“ (εˆ†ι˜)</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ζΆˆθ€—ε‘θ·―ι‡Œ</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
<tr>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2025-04-21</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">θ·‘ζ­₯</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">30</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">300</td>
</tr>
<tr>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2025-04-20</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">重訓</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">45</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">270</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
);
}