feat: implement frontend Web UI pages

- Add types for all API models (MealPlan, Recipe, Ingredient, etc.)
- Add API client with mealPlannerApi wrapper for all endpoints
- Implement Dashboard with weekly meal plan grid view
- Implement Pantry page with add/remove functionality
- Implement MealDetail page with recipe display
- Implement ShoppingList page with aisle grouping
- Add ShoppingList route to App.tsx
- Add vite-env.d.ts for Vite env type support
This commit is contained in:
2026-05-04 20:54:54 -07:00
parent 933a0cc9db
commit 08e196b0ab
8 changed files with 773 additions and 11 deletions
+149 -4
View File
@@ -1,8 +1,153 @@
export default function Dashboard() {
import { useQuery } from '@tanstack/react-query'
import { mealPlannerApi } from '../api'
import type { MealPlan, MealPlanItem } from '../types'
const DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
const MEAL_TYPES = ['breakfast', 'lunch', 'dinner'] as const
function MealCard({ item }: { item: MealPlanItem }) {
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold text-gray-900">This Week's Meal Plan</h1>
<p className="text-gray-500">Meal planning UI coming soon...</p>
<div className="bg-white rounded-lg shadow p-4 flex gap-4">
{item.recipe?.image_url && (
<img
src={item.recipe.image_url}
alt={item.recipe.name}
className="w-24 h-24 object-cover rounded-lg"
/>
)}
<div className="flex-1">
<h3 className="font-semibold text-gray-900">{item.recipe?.name || 'Unknown Recipe'}</h3>
{item.recipe && (
<p className="text-sm text-gray-500">
{item.recipe.total_time_minutes || (item.recipe.prep_time_minutes || 0) + (item.recipe.cook_time_minutes || 0)} min
{' · '}
{item.recipe.servings} servings
</p>
)}
<div className="mt-2 flex items-center gap-2">
<span className={`inline-flex px-2 py-1 text-xs rounded-full ${
item.approval_status === 'approved' ? 'bg-green-100 text-green-800' :
item.approval_status === 'denied' ? 'bg-red-100 text-red-800' :
item.approval_status === 'swapped' ? 'bg-yellow-100 text-yellow-800' :
'bg-gray-100 text-gray-800'
}`}>
{item.approval_status}
</span>
{item.estimated_cost && (
<span className="text-sm text-gray-600">${item.estimated_cost.toFixed(2)}</span>
)}
</div>
</div>
</div>
)
}
function DayColumn({ dayIndex, items }: { dayIndex: number; items: MealPlanItem[] }) {
return (
<div className="flex-1 min-w-[200px]">
<div className="bg-gray-100 rounded-t-lg px-4 py-2 font-semibold text-gray-700">
{DAY_NAMES[dayIndex]}
</div>
<div className="space-y-3 p-2">
{MEAL_TYPES.map(mealType => {
const item = items.find(i => i.meal_type === mealType)
return (
<div key={mealType} className="text-xs text-gray-500 uppercase">
{mealType}
{item ? <MealCard item={item} /> : <div className="bg-gray-50 border-2 border-dashed rounded-lg h-24" />}
</div>
)
})}
</div>
</div>
)
}
export default function Dashboard() {
const { data: mealPlan, isLoading } = useQuery<MealPlan | null>({
queryKey: ['mealPlan'],
queryFn: () => mealPlannerApi.meals.getPlanned().then(r => r.data),
})
if (isLoading) {
return (
<div className="flex justify-center items-center py-12">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" />
</div>
)
}
if (!mealPlan) {
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold text-gray-900">This Week's Meal Plan</h1>
<div className="bg-white rounded-lg shadow p-8 text-center">
<p className="text-gray-500 mb-4">No meal plan generated yet</p>
<button className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700">
Generate Meal Plan
</button>
</div>
</div>
)
}
const itemsByDay = Array.from({ length: 7 }, (_, i) =>
mealPlan.items.filter(item => item.day_of_week === i + 1)
)
return (
<div className="space-y-6">
<div className="flex justify-between items-center">
<h1 className="text-2xl font-bold text-gray-900">
Week of {new Date(mealPlan.week_start_date).toLocaleDateString()}
</h1>
<div className="flex gap-2">
<span className={`inline-flex px-3 py-1 text-sm rounded-full ${
mealPlan.status === 'approved' ? 'bg-green-100 text-green-800' :
mealPlan.status === 'locked' ? 'bg-blue-100 text-blue-800' :
mealPlan.status === 'pending_approval' ? 'bg-yellow-100 text-yellow-800' :
'bg-gray-100 text-gray-800'
}`}>
{mealPlan.status.replace('_', ' ')}
</span>
{mealPlan.total_estimated_cost && (
<span className="px-3 py-1 bg-gray-100 text-gray-800 rounded-full">
${mealPlan.total_estimated_cost.toFixed(2)} total
</span>
)}
</div>
</div>
<div className="bg-white rounded-lg shadow p-6">
<h2 className="text-lg font-semibold mb-4">Weekly Overview</h2>
<div className="overflow-x-auto">
<div className="flex gap-4 min-w-[1400px]">
{itemsByDay.map((items, index) => (
<DayColumn key={index} dayIndex={index} items={items} />
))}
</div>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="bg-white rounded-lg shadow p-6">
<h2 className="text-lg font-semibold mb-4">Shopping List</h2>
<a href="/shopping-list" className="text-blue-600 hover:text-blue-800">
View shopping list
</a>
</div>
<div className="bg-white rounded-lg shadow p-6">
<h2 className="text-lg font-semibold mb-4">Quick Actions</h2>
<div className="space-y-2">
<a href="/pantry" className="block text-blue-600 hover:text-blue-800">
Manage Pantry
</a>
<a href="/recipes" className="block text-blue-600 hover:text-blue-800">
Browse Recipes
</a>
</div>
</div>
</div>
</div>
)
}