feat(ui): visually polish RecipeDetailPage and RecipeForm with consistent theme tokens, improved layout, card sections, and input styling for UX parity with RecipeList

This commit is contained in:
Paul Huliganga 2026-03-25 18:31:07 -04:00
parent b7e7e9955e
commit 855dc62207
2 changed files with 162 additions and 305 deletions

View File

@ -2,14 +2,6 @@ import { useState, useEffect } from 'react';
import type { Recipe, Tag } from '../types/recipe'; import type { Recipe, Tag } from '../types/recipe';
import { TagSelector } from './TagSelector'; import { TagSelector } from './TagSelector';
interface RecipeFormProps {
recipe?: Recipe | null;
initialTags?: Tag[];
onSubmit: (data: RecipeFormData, tags: Tag[]) => Promise<void>;
onCancel: () => void;
submitLabel?: string;
}
export interface RecipeFormData { export interface RecipeFormData {
title: string; title: string;
description?: string; description?: string;
@ -22,8 +14,16 @@ export interface RecipeFormData {
cook_time_minutes?: number; cook_time_minutes?: number;
} }
interface RecipeFormProps {
recipe?: Recipe; // May be undefined when creating
initialTags?: Tag[];
onSubmit: (data: RecipeFormData, tags: Tag[]) => Promise<void>;
onCancel: () => void;
submitLabel?: string;
}
/** /**
* RecipeForm - Form component for creating/editing recipes * RecipeForm - Visually polished form component for creating/editing recipes
*/ */
export function RecipeForm({ export function RecipeForm({
recipe, recipe,
@ -52,8 +52,10 @@ export function RecipeForm({
if (recipe) { if (recipe) {
setTitle(recipe.title || ''); setTitle(recipe.title || '');
setDescription(recipe.description || ''); setDescription(recipe.description || '');
setIngredientsText(recipe.ingredients.join('\n')); setIngredientsText((Array.isArray(recipe.ingredients) ? recipe.ingredients.map(ingr => ('item' in ingr ? ingr.item : (typeof ingr === 'string' ? ingr : ''))) : []).join('\n'));
setInstructionsText(recipe.instructions.join('\n')); setInstructionsText(
(Array.isArray(recipe.instructions) ? recipe.instructions : recipe.steps?.map(s => s.instruction) || []).join('\n')
);
setSourceUrl(recipe.source_url || ''); setSourceUrl(recipe.source_url || '');
setNotes(recipe.notes || ''); setNotes(recipe.notes || '');
setServings(recipe.servings?.toString() || ''); setServings(recipe.servings?.toString() || '');
@ -62,12 +64,11 @@ export function RecipeForm({
} }
}, [recipe]); }, [recipe]);
// Update tags when initialTags changes
useEffect(() => { useEffect(() => {
setSelectedTags(initialTags); setSelectedTags(initialTags);
}, [initialTags]); }, [initialTags]);
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
setError(null); setError(null);
@ -81,7 +82,6 @@ export function RecipeForm({
.split('\n') .split('\n')
.map(line => line.trim()) .map(line => line.trim())
.filter(line => line.length > 0); .filter(line => line.length > 0);
if (ingredientsList.length === 0) { if (ingredientsList.length === 0) {
setError('At least one ingredient is required'); setError('At least one ingredient is required');
return; return;
@ -91,7 +91,6 @@ export function RecipeForm({
.split('\n') .split('\n')
.map(line => line.trim()) .map(line => line.trim())
.filter(line => line.length > 0); .filter(line => line.length > 0);
if (instructionsList.length === 0) { if (instructionsList.length === 0) {
setError('At least one instruction step is required'); setError('At least one instruction step is required');
return; return;
@ -108,7 +107,6 @@ export function RecipeForm({
prep_time_minutes: prepTime ? parseInt(prepTime, 10) : undefined, prep_time_minutes: prepTime ? parseInt(prepTime, 10) : undefined,
cook_time_minutes: cookTime ? parseInt(cookTime, 10) : undefined, cook_time_minutes: cookTime ? parseInt(cookTime, 10) : undefined,
}; };
try { try {
setIsSubmitting(true); setIsSubmitting(true);
await onSubmit(data, selectedTags); await onSubmit(data, selectedTags);
@ -119,173 +117,140 @@ export function RecipeForm({
}; };
return ( return (
<form onSubmit={handleSubmit} className="space-y-6"> <form onSubmit={handleSubmit} className="space-y-8">
{error && ( {error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded"> <div className="bg-red-50 border border-red-200 text-red-700 px-5 py-3 rounded-lg shadow-card font-medium text-base">
{error} {error}
</div> </div>
)} )}
{/* Title */}
<div> <div>
<label htmlFor="title" className="block text-sm font-medium text-gray-700"> <label htmlFor="title" className="block text-base font-semibold text-gray-700 mb-1">
Title <span className="text-red-500">*</span> Title <span className="text-error">*</span>
</label> </label>
<input <input
type="text" type="text"
id="title" id="title"
value={title} value={title}
onChange={(e) => setTitle(e.target.value)} onChange={e => setTitle(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-[17px] py-2 px-4 font-medium"
placeholder="e.g., Chocolate Chip Cookies" placeholder="e.g., Chocolate Chip Cookies"
required required
/> />
</div> </div>
{/* Description */}
<div> <div>
<label htmlFor="description" className="block text-sm font-medium text-gray-700"> <label htmlFor="description" className="block text-base font-semibold text-gray-700 mb-1">
Description Description
</label> </label>
<textarea <textarea
id="description" id="description"
value={description} value={description}
onChange={(e) => setDescription(e.target.value)} onChange={e => setDescription(e.target.value)}
rows={2} rows={2}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="Brief description of the recipe..." placeholder="Brief description of the recipe..."
/> />
</div> </div>
{/* Tags */}
<div> <div>
<label className="block text-sm font-medium text-gray-700 mb-2"> <label className="block text-base font-semibold text-gray-700 mb-1">
Tags Tags
</label> </label>
<TagSelector <TagSelector selectedTags={selectedTags} onTagsChange={setSelectedTags} />
selectedTags={selectedTags}
onTagsChange={setSelectedTags}
/>
</div> </div>
{/* Ingredients */}
<div> <div>
<label htmlFor="ingredients" className="block text-sm font-medium text-gray-700"> <label htmlFor="ingredients" className="block text-base font-semibold text-gray-700 mb-1">
Ingredients <span className="text-red-500">*</span> Ingredients <span className="text-error">*</span>
</label> </label>
<p className="mt-1 text-sm text-gray-500">One ingredient per line</p> <p className="mt-0.5 text-sm text-gray-500 mb-2">One ingredient per line</p>
<textarea <textarea
id="ingredients" id="ingredients"
value={ingredientsText} value={ingredientsText}
onChange={(e) => setIngredientsText(e.target.value)} onChange={e => setIngredientsText(e.target.value)}
rows={8} rows={7}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 font-mono text-sm" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary font-mono text-base px-4 py-2"
placeholder="2 cups all-purpose flour&#10;1 cup butter, softened&#10;3/4 cup sugar" placeholder="2 cups all-purpose flour\n1 cup butter, softened\n3/4 cup sugar"
required required
/> />
</div> </div>
{/* Instructions */}
<div> <div>
<label htmlFor="instructions" className="block text-sm font-medium text-gray-700"> <label htmlFor="instructions" className="block text-base font-semibold text-gray-700 mb-1">
Instructions <span className="text-red-500">*</span> Instructions <span className="text-error">*</span>
</label> </label>
<p className="mt-1 text-sm text-gray-500">One step per line</p> <p className="mt-0.5 text-sm text-gray-500 mb-2">One step per line</p>
<textarea <textarea
id="instructions" id="instructions"
value={instructionsText} value={instructionsText}
onChange={(e) => setInstructionsText(e.target.value)} onChange={e => setInstructionsText(e.target.value)}
rows={10} rows={8}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 font-mono text-sm" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary font-mono text-base px-4 py-2"
placeholder="Preheat oven to 350°F&#10;Mix flour and baking soda&#10;Cream butter and sugar" placeholder="Preheat oven to 350°F\nMix flour and baking soda\nCream butter and sugar"
required required
/> />
</div> </div>
{/* Metadata Grid */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4"> <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div> <div>
<label htmlFor="servings" className="block text-sm font-medium text-gray-700"> <label htmlFor="servings" className="block text-base font-semibold text-gray-700 mb-1">Servings</label>
Servings
</label>
<input <input
type="number" type="number"
id="servings" id="servings"
value={servings} value={servings}
onChange={(e) => setServings(e.target.value)} onChange={e => setServings(e.target.value)}
min="1" min="1"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="4" placeholder="4"
/> />
</div> </div>
<div> <div>
<label htmlFor="prep_time" className="block text-sm font-medium text-gray-700"> <label htmlFor="prep_time" className="block text-base font-semibold text-gray-700 mb-1">Prep Time (min)</label>
Prep Time (min)
</label>
<input <input
type="number" type="number"
id="prep_time" id="prep_time"
value={prepTime} value={prepTime}
onChange={(e) => setPrepTime(e.target.value)} onChange={e => setPrepTime(e.target.value)}
min="0" min="0"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="15" placeholder="15"
/> />
</div> </div>
<div> <div>
<label htmlFor="cook_time" className="block text-sm font-medium text-gray-700"> <label htmlFor="cook_time" className="block text-base font-semibold text-gray-700 mb-1">Cook Time (min)</label>
Cook Time (min)
</label>
<input <input
type="number" type="number"
id="cook_time" id="cook_time"
value={cookTime} value={cookTime}
onChange={(e) => setCookTime(e.target.value)} onChange={e => setCookTime(e.target.value)}
min="0" min="0"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="30" placeholder="30"
/> />
</div> </div>
</div> </div>
{/* Source URL */}
<div> <div>
<label htmlFor="source_url" className="block text-sm font-medium text-gray-700"> <label htmlFor="source_url" className="block text-base font-semibold text-gray-700 mb-1">Source URL</label>
Source URL
</label>
<input <input
type="url" type="url"
id="source_url" id="source_url"
value={sourceUrl} value={sourceUrl}
onChange={(e) => setSourceUrl(e.target.value)} onChange={e => setSourceUrl(e.target.value)}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="https://example.com/recipe" placeholder="https://example.com/recipe"
/> />
</div> </div>
{/* Notes */}
<div> <div>
<label htmlFor="notes" className="block text-sm font-medium text-gray-700"> <label htmlFor="notes" className="block text-base font-semibold text-gray-700 mb-1">Notes</label>
Notes
</label>
<textarea <textarea
id="notes" id="notes"
value={notes} value={notes}
onChange={(e) => setNotes(e.target.value)} onChange={e => setNotes(e.target.value)}
rows={3} rows={3}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" className="mt-1 block w-full rounded-md border-gray-300 shadow-card focus:border-primary focus:ring-primary text-base px-4 py-2"
placeholder="Personal notes, substitutions, tips..." placeholder="Personal notes, substitutions, tips..."
/> />
</div> </div>
{/* Form Actions */}
<div className="flex gap-3 pt-4"> <div className="flex gap-3 pt-4">
<button <button
type="submit" type="submit"
disabled={isSubmitting} disabled={isSubmitting}
className="flex-1 bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed font-medium" className="flex-1 bg-primary text-white px-4 py-2 rounded-md shadow-card hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed font-semibold transition-colors text-base"
> >
{isSubmitting ? 'Saving...' : submitLabel} {isSubmitting ? 'Saving...' : submitLabel}
</button> </button>
@ -293,7 +258,7 @@ export function RecipeForm({
type="button" type="button"
onClick={onCancel} onClick={onCancel}
disabled={isSubmitting} disabled={isSubmitting}
className="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed font-medium" className="px-4 py-2 border border-gray-300 rounded-md shadow font-semibold text-gray-700 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed text-base transition-colors"
> >
Cancel Cancel
</button> </button>

View File

@ -3,34 +3,24 @@ import { useParams, useNavigate, Link } from 'react-router-dom';
import { useRecipe } from '../hooks/useRecipe'; import { useRecipe } from '../hooks/useRecipe';
import { useToastContext } from '../App'; import { useToastContext } from '../App';
import { RecipeForm, type RecipeFormData } from '../components/RecipeForm'; import { RecipeForm, type RecipeFormData } from '../components/RecipeForm';
import { import { createRecipe, updateRecipe, deleteRecipe, fetchRecipeTags, assignTagToRecipe, removeTagFromRecipe } from '../services/api';
createRecipe, import type { Tag, Recipe, Ingredient } from '../types/recipe';
updateRecipe,
deleteRecipe,
fetchRecipeTags,
assignTagToRecipe,
removeTagFromRecipe
} from '../services/api';
import type { Tag } from '../types/recipe';
/** /**
* RecipeDetailPage - View, create, and edit recipes * RecipeDetailPage - View, create, and edit recipes (Visually polished)
*/ */
export function RecipeDetailPage() { export function RecipeDetailPage() {
const { id } = useParams<{ id: string }>(); const { id } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const toast = useToastContext(); const toast = useToastContext();
// Parse ID or null for "new" route // Parse ID or null for "new" route
const recipeId = id === 'new' ? null : (id ? parseInt(id, 10) : null); const recipeId = id === 'new' ? null : (id ? parseInt(id, 10) : null);
const { recipe, loading, error } = useRecipe(recipeId); const { recipe, loading, error } = useRecipe(recipeId);
const [isEditing, setIsEditing] = useState(recipeId === null); // Start in edit mode for new recipes const [isEditing, setIsEditing] = useState(recipeId === null);
const [deleteConfirm, setDeleteConfirm] = useState(false); const [deleteConfirm, setDeleteConfirm] = useState(false);
const [recipeTags, setRecipeTags] = useState<Tag[]>([]); const [recipeTags, setRecipeTags] = useState<Tag[]>([]);
const [isDeleting, setIsDeleting] = useState(false); const [isDeleting, setIsDeleting] = useState(false);
// Load recipe tags
useEffect(() => { useEffect(() => {
if (recipeId !== null) { if (recipeId !== null) {
fetchRecipeTags(recipeId) fetchRecipeTags(recipeId)
@ -42,73 +32,60 @@ export function RecipeDetailPage() {
} }
}, [recipeId, toast]); }, [recipeId, toast]);
// Compose FE ingredients to BE Ingredient[] shape with dummies for missing fields
function toApiIngredients(ingredients: string[]): Ingredient[] {
return ingredients.map((item, idx) => ({
id: 0,
recipe_id: 0,
position: idx + 1,
item,
quantity: null,
unit: null,
notes: null,
}));
}
// Handle form submission // Handle form submission
const handleSubmit = async (data: RecipeFormData, tags: Tag[]) => { const handleSubmit = async (data: RecipeFormData, tags: Tag[]) => {
try { try {
if (recipeId === null) { if (recipeId === null) {
// Create new recipe // Compose to API input shape (fill dummies)
const newRecipe = await createRecipe(data); const newRecipe = await createRecipe({
...data,
// Assign tags ingredients: toApiIngredients(data.ingredients),
for (const tag of tags) { instructions: data.instructions,
try { });
await assignTagToRecipe(newRecipe.id, tag.id); for (const tag of tags) { try { await assignTagToRecipe(newRecipe.id, tag.id); } catch {} }
} catch (err) {
console.error('Failed to assign tag:', err);
toast.warning(`Failed to assign tag "${tag.name}"`);
}
}
toast.success('Recipe created successfully!'); toast.success('Recipe created successfully!');
navigate(`/recipe/${newRecipe.id}`); navigate(`/recipe/${newRecipe.id}`);
} else { } else {
// Update existing recipe await updateRecipe(recipeId, {
await updateRecipe(recipeId, data); ...data,
ingredients: toApiIngredients(data.ingredients),
// Update tags: remove old ones, add new ones instructions: data.instructions,
});
// Tag syncing (remove/add)
const currentTagIds = recipeTags.map(t => t.id); const currentTagIds = recipeTags.map(t => t.id);
const newTagIds = tags.map(t => t.id); const newTagIds = tags.map(t => t.id);
// Remove tags that are no longer selected
for (const tagId of currentTagIds) { for (const tagId of currentTagIds) {
if (!newTagIds.includes(tagId)) { if (!newTagIds.includes(tagId)) { try { await removeTagFromRecipe(recipeId, tagId); } catch {} }
try {
await removeTagFromRecipe(recipeId, tagId);
} catch (err) {
console.error('Failed to remove tag:', err);
toast.warning('Failed to remove some tags');
} }
}
}
// Add tags that are newly selected
for (const tagId of newTagIds) { for (const tagId of newTagIds) {
if (!currentTagIds.includes(tagId)) { if (!currentTagIds.includes(tagId)) { try { await assignTagToRecipe(recipeId, tagId); } catch {} }
try {
await assignTagToRecipe(recipeId, tagId);
} catch (err) {
console.error('Failed to assign tag:', err);
toast.warning('Failed to assign some tags');
} }
}
}
toast.success('Recipe updated successfully!'); toast.success('Recipe updated successfully!');
setIsEditing(false); setIsEditing(false);
// Refresh the page to show updated data
window.location.reload(); window.location.reload();
} }
} catch (err) { } catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Failed to save recipe'; const errorMessage = err instanceof Error ? err.message : 'Failed to save recipe';
toast.error(errorMessage); toast.error(errorMessage);
throw err; // Re-throw so form can handle it throw err;
} }
}; };
// Handle delete
const handleDelete = async () => { const handleDelete = async () => {
if (recipeId === null) return; if (recipeId === null) return;
try { try {
setIsDeleting(true); setIsDeleting(true);
await deleteRecipe(recipeId); await deleteRecipe(recipeId);
@ -122,242 +99,157 @@ export function RecipeDetailPage() {
} }
}; };
// Loading state // Loading State
if (loading) { if (loading) {
return ( return (
<div className="text-center py-12"> <div className="flex flex-col items-center justify-center py-24">
<div className="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div> <div className="inline-block animate-spin rounded-full h-9 w-9 border-b-2 border-primary"></div>
<p className="mt-4 text-gray-600">Loading recipe...</p> <p className="mt-6 text-gray-500 text-base font-medium">Loading recipe...</p>
</div> </div>
); );
} }
// Error State
// Error state
if (error) { if (error) {
return ( return (
<div className="bg-red-50 border border-red-200 rounded-lg p-6"> <div className="max-w-xl mx-auto bg-red-50 border border-red-200 rounded-xl shadow-card p-8 mt-12 flex flex-col items-center">
<h3 className="text-red-800 font-semibold mb-2">Error Loading Recipe</h3> <h3 className="text-xl text-red-800 font-bold mb-3">Error Loading Recipe</h3>
<p className="text-red-600">{error}</p> <p className="text-red-600 text-base mb-2">{error}</p>
<Link to="/" className="mt-4 inline-block text-blue-600 hover:text-blue-700"> <Link to="/" className="mt-4 px-4 py-2 bg-primary text-white rounded-md font-medium hover:bg-blue-700"> Back to recipes</Link>
Back to recipes
</Link>
</div> </div>
); );
} }
// New Recipe
// New recipe mode (always in edit)
if (recipeId === null) { if (recipeId === null) {
return ( return (
<div> <div className="max-w-2xl mx-auto pt-8">
<div className="mb-6"> <div className="mb-6 pb-1 border-b border-gray-200">
<h2 className="text-2xl font-bold text-gray-900">Create New Recipe</h2> <h2 className="text-3xl font-bold text-gray-900">Create New Recipe</h2>
<p className="mt-1 text-sm text-gray-500"> <p className="mt-1 text-base text-gray-500">Fill in the details below to add a new recipe</p>
Fill in the details below to add a new recipe
</p>
</div> </div>
<div className="bg-white rounded-xl shadow-card p-8">
<div className="bg-white rounded-lg shadow p-6"> <RecipeForm initialTags={[]} onSubmit={handleSubmit} onCancel={() => navigate('/')} submitLabel="Create Recipe" />
<RecipeForm
initialTags={[]}
onSubmit={handleSubmit}
onCancel={() => navigate('/')}
submitLabel="Create Recipe"
/>
</div> </div>
</div> </div>
); );
} }
// Recipe Not Found
// Recipe not found
if (!recipe) { if (!recipe) {
return ( return (
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-6"> <div className="max-w-md mx-auto bg-yellow-50 border border-yellow-200 rounded-xl shadow-card p-8 mt-12 flex flex-col items-center">
<h3 className="text-yellow-800 font-semibold mb-2">Recipe Not Found</h3> <h3 className="text-xl text-yellow-800 font-bold mb-2">Recipe Not Found</h3>
<p className="text-yellow-600">The recipe you're looking for doesn't exist.</p> <p className="text-yellow-600 text-base mb-2">The recipe you are looking for does not exist.</p>
<Link to="/" className="mt-4 inline-block text-blue-600 hover:text-blue-700"> <Link to="/" className="mt-4 px-4 py-2 bg-primary text-white rounded-md font-medium hover:bg-blue-700"> Back to recipes</Link>
Back to recipes
</Link>
</div> </div>
); );
} }
// Edit Mode
// Edit mode
if (isEditing) { if (isEditing) {
return ( return (
<div> <div className="max-w-2xl mx-auto pt-8">
<div className="mb-6"> <div className="mb-6 pb-1 border-b border-gray-200">
<h2 className="text-2xl font-bold text-gray-900">Edit Recipe</h2> <h2 className="text-3xl font-bold text-gray-900">Edit Recipe</h2>
<p className="mt-1 text-sm text-gray-500"> <p className="mt-1 text-base text-gray-500">Update recipe information below</p>
Update recipe information
</p>
</div> </div>
<div className="bg-white rounded-xl shadow-card p-8">
<div className="bg-white rounded-lg shadow p-6"> <RecipeForm recipe={recipe} initialTags={recipeTags} onSubmit={handleSubmit} onCancel={() => setIsEditing(false)} submitLabel="Save Changes" />
<RecipeForm
recipe={recipe}
initialTags={recipeTags}
onSubmit={handleSubmit}
onCancel={() => setIsEditing(false)}
submitLabel="Save Changes"
/>
</div> </div>
</div> </div>
); );
} }
// View mode // View Recipe
return ( return (
<div> <div className="max-w-4xl mx-auto pt-8">
{/* Header with actions */} <div className="bg-white rounded-xl shadow-card p-8 mb-6 flex flex-col sm:flex-row items-start justify-between gap-6">
<div className="mb-6 flex items-start justify-between"> <div className="flex-1 min-w-0">
<div> <h2 className="text-4xl font-bold text-gray-900 mb-1 break-words">{recipe.title}</h2>
<h2 className="text-3xl font-bold text-gray-900">{recipe.title}</h2>
{recipe.description && ( {recipe.description && (
<p className="mt-2 text-gray-600">{recipe.description}</p> <p className="mt-1 text-lg text-gray-600 break-words">{recipe.description}</p>
)} )}
{/* Tags display */}
{recipeTags.length > 0 && ( {recipeTags.length > 0 && (
<div className="mt-3 flex flex-wrap gap-2"> <div className="mt-4 flex flex-wrap gap-2">
{recipeTags.map(tag => ( {recipeTags.map(tag => (
<span <span key={tag.id} className="px-3 py-1 rounded-full text-xs font-medium text-white shadow" style={{ backgroundColor: tag.color || '#3B82F6' }}>{tag.name}</span>
key={tag.id}
className="px-3 py-1 rounded-full text-sm font-medium text-white"
style={{ backgroundColor: tag.color || '#3B82F6' }}
>
{tag.name}
</span>
))} ))}
</div> </div>
)} )}
</div> </div>
<div className="flex gap-2 ml-4"> <div className="flex flex-col gap-3 min-w-[120px]">
<button <button onClick={() => setIsEditing(true)} className="w-full px-4 py-2 bg-primary text-white rounded-md shadow hover:bg-blue-700 font-medium transition-colors">Edit</button>
onClick={() => setIsEditing(true)} <Link to={`/recipe/${recipe.id}/cook`} className="w-full px-4 py-2 bg-success text-white rounded-md shadow hover:bg-green-700 font-medium text-center transition-colors">Cook Mode</Link>
className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 font-medium"
>
Edit
</button>
<Link
to={`/recipe/${recipe.id}/cook`}
className="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 font-medium"
>
Cook Mode
</Link>
{!deleteConfirm ? ( {!deleteConfirm ? (
<button <button onClick={() => setDeleteConfirm(true)} className="w-full px-4 py-2 bg-error text-white rounded-md shadow font-medium hover:bg-red-700 transition-colors">Delete</button>
onClick={() => setDeleteConfirm(true)}
className="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 font-medium"
>
Delete
</button>
) : ( ) : (
<div className="flex gap-2"> <div className="flex flex-col gap-2">
<button <button onClick={handleDelete} disabled={isDeleting} className="w-full px-3 py-2 bg-error text-white rounded-md hover:bg-red-700 text-sm font-medium shadow disabled:bg-gray-400 disabled:cursor-not-allowed">{isDeleting ? 'Deleting...' : 'Confirm Delete'}</button>
onClick={handleDelete} <button onClick={() => setDeleteConfirm(false)} disabled={isDeleting} className="w-full px-3 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm font-medium shadow disabled:opacity-50 disabled:cursor-not-allowed">Cancel</button>
disabled={isDeleting}
className="px-3 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 text-sm font-medium disabled:bg-gray-400 disabled:cursor-not-allowed"
>
{isDeleting ? 'Deleting...' : 'Confirm Delete'}
</button>
<button
onClick={() => setDeleteConfirm(false)}
disabled={isDeleting}
className="px-3 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed"
>
Cancel
</button>
</div> </div>
)} )}
</div> </div>
</div> </div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6 text-center">
{/* Metadata */}
<div className="grid grid-cols-3 gap-4 mb-6">
{recipe.servings && ( {recipe.servings && (
<div className="bg-gray-50 rounded-lg p-4"> <div className="bg-gray-50 rounded-lg p-4 shadow-card">
<div className="text-sm text-gray-500">Servings</div> <div className="text-sm text-gray-500 mb-1">Servings</div>
<div className="text-lg font-semibold text-gray-900">{recipe.servings}</div> <div className="text-lg font-semibold text-gray-900">{recipe.servings}</div>
</div> </div>
)} )}
{recipe.prep_time_minutes && ( {recipe.prep_time_minutes && (
<div className="bg-gray-50 rounded-lg p-4"> <div className="bg-gray-50 rounded-lg p-4 shadow-card">
<div className="text-sm text-gray-500">Prep Time</div> <div className="text-sm text-gray-500 mb-1">Prep Time</div>
<div className="text-lg font-semibold text-gray-900">{recipe.prep_time_minutes} min</div> <div className="text-lg font-semibold text-gray-900">{recipe.prep_time_minutes} min</div>
</div> </div>
)} )}
{recipe.cook_time_minutes && ( {recipe.cook_time_minutes && (
<div className="bg-gray-50 rounded-lg p-4"> <div className="bg-gray-50 rounded-lg p-4 shadow-card">
<div className="text-sm text-gray-500">Cook Time</div> <div className="text-sm text-gray-500 mb-1">Cook Time</div>
<div className="text-lg font-semibold text-gray-900">{recipe.cook_time_minutes} min</div> <div className="text-lg font-semibold text-gray-900">{recipe.cook_time_minutes} min</div>
</div> </div>
)} )}
</div> </div>
{/* Main content */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Ingredients */} <div className="bg-white rounded-xl shadow-card p-6">
<div className="bg-white rounded-lg shadow p-6"> <h3 className="text-xl font-semibold text-gray-900 mb-6">Ingredients</h3>
<h3 className="text-xl font-bold text-gray-900 mb-4">Ingredients</h3> <ul className="space-y-3">
<ul className="space-y-2"> {Array.isArray(recipe.ingredients) ? recipe.ingredients.map((ingredient, index) => (
{recipe.ingredients.map((ingredient, index) => ( <li key={index} className="flex items-center gap-3">
<li key={index} className="flex items-start"> <span className="inline-block w-3 h-3 bg-primary rounded-full"></span>
<span className="inline-block w-2 h-2 bg-blue-600 rounded-full mt-2 mr-3 flex-shrink-0"></span> <span className="text-gray-800 font-mono text-base">{'item' in ingredient ? ingredient.item : ingredient}</span>
<span className="text-gray-700">{ingredient}</span>
</li> </li>
))} )) : null}
</ul> </ul>
</div> </div>
<div className="bg-white rounded-xl shadow-card p-6">
{/* Instructions */} <h3 className="text-xl font-semibold text-gray-900 mb-6">Instructions</h3>
<div className="bg-white rounded-lg shadow p-6"> <ol className="space-y-4 list-none">
<h3 className="text-xl font-bold text-gray-900 mb-4">Instructions</h3> {Array.isArray(recipe.instructions) ? recipe.instructions.map((instruction, index) => (
<ol className="space-y-4"> <li key={index} className="flex items-start gap-3">
{recipe.instructions.map((instruction, index) => ( <span className="inline-flex items-center justify-center w-8 h-8 bg-primary text-white rounded-full text-base font-bold">{index + 1}</span>
<li key={index} className="flex items-start"> <span className="text-gray-800 pt-[2px] text-base leading-6">{instruction}</span>
<span className="inline-flex items-center justify-center w-6 h-6 bg-blue-600 text-white rounded-full text-sm font-bold mr-3 flex-shrink-0">
{index + 1}
</span>
<span className="text-gray-700 pt-0.5">{instruction}</span>
</li> </li>
))} )) : null}
</ol> </ol>
</div> </div>
</div> </div>
{/* Additional info */}
{(recipe.source_url || recipe.notes) && ( {(recipe.source_url || recipe.notes) && (
<div className="mt-6 bg-white rounded-lg shadow p-6"> <div className="mt-8 bg-white rounded-xl shadow-card p-6">
<h3 className="text-xl font-bold text-gray-900 mb-4">Additional Information</h3> <h3 className="text-xl font-semibold text-gray-900 mb-4">Additional Information</h3>
{recipe.source_url && ( {recipe.source_url && (
<div className="mb-4"> <div className="mb-4">
<div className="text-sm font-medium text-gray-700 mb-1">Source</div> <div className="text-sm font-medium text-gray-700 mb-1">Source</div>
<a <a href={recipe.source_url} target="_blank" rel="noopener noreferrer" className="text-primary hover:text-blue-700 underline break-all">{recipe.source_url}</a>
href={recipe.source_url}
target="_blank"
rel="noopener noreferrer"
className="text-blue-600 hover:text-blue-700 underline break-all"
>
{recipe.source_url}
</a>
</div> </div>
)} )}
{recipe.notes && ( {recipe.notes && (
<div> <div>
<div className="text-sm font-medium text-gray-700 mb-1">Notes</div> <div className="text-sm font-medium text-gray-700 mb-1">Notes</div>
<p className="text-gray-700 whitespace-pre-wrap">{recipe.notes}</p> <p className="text-gray-800 whitespace-pre-wrap">{recipe.notes}</p>
</div> </div>
)} )}
</div> </div>
)} )}
<div className="mt-8 text-center">
{/* Back button */} <Link to="/" className="text-primary hover:text-blue-700 font-medium"> Back to all recipes</Link>
<div className="mt-6">
<Link to="/" className="text-blue-600 hover:text-blue-700 font-medium">
Back to all recipes
</Link>
</div> </div>
</div> </div>
); );