Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
name="description"
content="Turn the ingredients you already have into a recipe, powered by Google Gemini."
/>
<!-- Apply the saved or system theme before first paint, so the page never flashes the wrong theme -->
<script>
try {
const saved = localStorage.getItem("theme");
const dark = saved ? saved === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
document.documentElement.classList.toggle("dark", dark);
} catch {}
</script>
</head>
<body class="antialiased">
<div id="root"></div>
Expand Down
132 changes: 46 additions & 86 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useState } from 'react';
import FilterOptions from '@/components/FilterOptions';
import IngredientInput from '@/components/IngredientInput';
import RecipeDisplay from '@/components/RecipeDisplay';
import FilterOptions from '@/components/FilterOptions';
import { Recipe } from '@/types/recipe';
import ThemeToggle from '@/components/ThemeToggle';
import { Button } from '@/components/ui/Button';
import { ApiService } from '@/services/api';
import type { FilterOptions as Filters, Recipe } from '@/types/recipe';

const DEFAULT_FILTERS: Filters = {
dietary_preferences: [],
max_cooking_time: null,
allow_external_ingredients: false,
};

export default function App() {
const [ingredients, setIngredients] = useState<string[]>([]);
const [filters, setFilters] = useState({
dietary_preferences: [] as string[],
max_cooking_time: null as number | null,
allow_external_ingredients: false
});
const [filters, setFilters] = useState<Filters>(DEFAULT_FILTERS);
const [recipe, setRecipe] = useState<Recipe | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -42,95 +46,51 @@ export default function App() {

const handleReset = () => {
setIngredients([]);
setFilters({
dietary_preferences: [],
max_cooking_time: null,
allow_external_ingredients: false
});
setFilters(DEFAULT_FILTERS);
setRecipe(null);
setError(null);
};

return (
<div className="min-h-screen bg-gradient-to-br from-orange-50 to-red-50">
<div className="container mx-auto px-4 py-8">
{/* Header */}
<div className="text-center mb-8">
<h1 className="text-4xl font-bold text-gray-800 mb-2">
🍳 Cookable
</h1>
<p className="text-gray-600 text-lg">
Enter your available ingredients and get AI-powered recipe suggestions
</p>
</div>

{/* Main Content */}
<div className="max-w-4xl mx-auto">
{/* Step 1: Ingredient Input */}
<div className="bg-white rounded-lg shadow-lg p-6 mb-6">
<h2 className="text-2xl font-semibold text-gray-800 mb-4">
1️⃣ Enter Your Ingredients
</h2>
<IngredientInput
ingredients={ingredients}
onIngredientsChange={setIngredients}
/>
<div className="min-h-screen px-4 pt-14 pb-20 sm:px-6">
<main className="mx-auto flex max-w-3xl flex-col gap-6">
<header className="flex items-start justify-between gap-4 pb-5">
<div className="flex flex-col gap-3.5">
<h1 className="text-6xl leading-none font-extrabold tracking-tighter sm:text-7xl">
Cook<span className="text-accent">able</span>
</h1>
<p className="text-lg text-muted">Your ingredients in. A recipe out.</p>
</div>
<ThemeToggle />
</header>

{/* Step 2: Filter Options */}
<div className="bg-white rounded-lg shadow-lg p-6 mb-6">
<h2 className="text-2xl font-semibold text-gray-800 mb-4">
2️⃣ Optional Filters
</h2>
<FilterOptions
filters={filters}
onFiltersChange={setFilters}
/>
</div>

{/* Step 3: Get Recipe Button */}
<div className="text-center mb-6">
<button
type="button"
onClick={handleGetRecipe}
disabled={loading || ingredients.length === 0}
className="bg-orange-500 hover:bg-orange-600 disabled:bg-gray-400 text-white font-bold py-3 px-8 rounded-lg text-lg transition-colors duration-200"
>
{loading ? '🍳 Cooking up a recipe...' : '🍽️ Get Recipe Recommendation'}
</button>
</div>
<IngredientInput ingredients={ingredients} onIngredientsChange={setIngredients} />
<FilterOptions filters={filters} onFiltersChange={setFilters} />

{/* Error Display */}
{error && (
<div role="alert" className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6">
{error}
</div>
)}
<Button
variant="primary"
onClick={handleGetRecipe}
disabled={loading || ingredients.length === 0}
className="h-16 text-xl tracking-tight"
>
{loading ? 'Cooking up a recipe...' : 'Get my recipe →'}
</Button>

{/* Step 4: Recipe Display */}
{recipe && (
<div className="bg-white rounded-lg shadow-lg p-6 mb-6">
<h2 className="text-2xl font-semibold text-gray-800 mb-4">
3️⃣ Your Recipe
</h2>
<RecipeDisplay recipe={recipe} />
</div>
)}
{error && (
<div role="alert" className="rounded-xl border-2 border-danger bg-surface px-4 py-3 font-medium text-danger">
{error}
</div>
)}

{/* Reset Button */}
{recipe && (
<div className="text-center">
<button
type="button"
onClick={handleReset}
className="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-6 rounded-lg transition-colors duration-200"
>
🔄 Start Over
</button>
</div>
)}
</div>
</div>
{recipe && (
<>
<RecipeDisplay recipe={recipe} />
<Button variant="outline" onClick={handleReset} className="h-12 self-center px-6">
Start over
</Button>
</>
)}
</main>
</div>
);
}
187 changes: 61 additions & 126 deletions frontend/src/components/FilterOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,142 +1,77 @@
import { FilterOptions as FilterOptionsType } from '@/types/recipe';
import { Card, StepHeading } from '@/components/ui/Card';
import { ToggleChip } from '@/components/ui/Chip';
import { fieldClass } from '@/components/ui/field';
import type { FilterOptions as Filters } from '@/types/recipe';

interface FilterOptionsProps {
filters: FilterOptionsType & { allow_external_ingredients: boolean };
onFiltersChange: (filters: FilterOptionsType & { allow_external_ingredients: boolean }) => void;
}

const dietaryOptions = [
{ value: 'vegetarian', label: '🥬 Vegetarian' },
{ value: 'vegan', label: '🌱 Vegan' },
{ value: 'gluten-free', label: '🌾 Gluten-Free' },
{ value: 'dairy-free', label: '🥛 Dairy-Free' },
{ value: 'low-carb', label: '🍞 Low-Carb' },
{ value: 'quick', label: '⚡ Quick (< 30 min)' },
const DIETARY_OPTIONS = [
{ value: 'vegetarian', label: 'Vegetarian' },
{ value: 'vegan', label: 'Vegan' },
{ value: 'gluten-free', label: 'Gluten-free' },
{ value: 'dairy-free', label: 'Dairy-free' },
{ value: 'low-carb', label: 'Low-carb' },
];

const cookingTimeOptions = [
{ value: 15, label: '15 minutes' },
{ value: 30, label: '30 minutes' },
{ value: 45, label: '45 minutes' },
{ value: 60, label: '1 hour' },
{ value: 90, label: '1.5 hours' },
];
const COOKING_TIMES = [15, 30, 45, 60, 90];

interface FilterOptionsProps {
filters: Filters;
onFiltersChange: (filters: Filters) => void;
}

export default function FilterOptions({ filters, onFiltersChange }: FilterOptionsProps) {
const handleDietaryPreferenceChange = (preference: string) => {
const newPreferences = filters.dietary_preferences.includes(preference)
? filters.dietary_preferences.filter(p => p !== preference)
: [...filters.dietary_preferences, preference];

onFiltersChange({
...filters,
dietary_preferences: newPreferences
});
};
const update = (changes: Partial<Filters>) => onFiltersChange({ ...filters, ...changes });

const handleCookingTimeChange = (time: number | null) => {
onFiltersChange({
...filters,
max_cooking_time: time
const togglePreference = (preference: string) => {
const current = filters.dietary_preferences;
update({
dietary_preferences: current.includes(preference)
? current.filter((p) => p !== preference)
: [...current, preference],
});
};

return (
<div className="space-y-6">
{/* External Ingredients Toggle */}
<div>
<label className="flex items-center justify-between cursor-pointer">
<span className="text-lg font-semibold text-gray-700">Suggest recipes with extra ingredients?</span>
<div className="relative">
<input
type="checkbox"
className="sr-only peer"
checked={filters.allow_external_ingredients}
onChange={(e) => onFiltersChange({ ...filters, allow_external_ingredients: e.target.checked })}
/>
<div className="block bg-gray-200 peer-checked:bg-orange-500 w-14 h-8 rounded-full transition-colors"></div>
<div className="dot absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition-transform peer-checked:translate-x-6"></div>
</div>
</label>
<p className="text-sm text-gray-500 mt-1">
If enabled, we&apos;ll suggest recipes that might require a few extra items, and we&apos;ll provide a shopping list for them.
</p>
</div>

{/* Dietary Preferences */}
<div>
<h3 className="text-lg font-semibold text-gray-700 mb-3">Dietary Preferences:</h3>
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
{dietaryOptions.map((option) => (
<label
key={option.value}
className="flex items-center space-x-2 cursor-pointer"
>
<input
type="checkbox"
checked={filters.dietary_preferences.includes(option.value)}
onChange={() => handleDietaryPreferenceChange(option.value)}
className="w-4 h-4 text-orange-600 bg-gray-100 border-gray-300 rounded focus:ring-orange-500 focus:ring-2"
/>
<span className="text-sm text-gray-700">{option.label}</span>
</label>
))}
</div>
</div>
<Card>
<StepHeading step={2} title="Filters" hint="optional" />

{/* Cooking Time */}
<div>
<h3 className="text-lg font-semibold text-gray-700 mb-3">Maximum Cooking Time:</h3>
<div className="flex flex-wrap gap-2">
<button
type="button"
onClick={() => handleCookingTimeChange(null)}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors duration-200 ${
filters.max_cooking_time === null
? 'bg-orange-500 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'
}`}
<div className="flex flex-wrap gap-2">
{DIETARY_OPTIONS.map(({ value, label }) => (
<ToggleChip
key={value}
selected={filters.dietary_preferences.includes(value)}
onClick={() => togglePreference(value)}
>
No Limit
</button>
{cookingTimeOptions.map((option) => (
<button
type="button"
key={option.value}
onClick={() => handleCookingTimeChange(option.value)}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors duration-200 ${
filters.max_cooking_time === option.value
? 'bg-orange-500 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'
}`}
>
{option.label}
</button>
))}
</div>
{label}
</ToggleChip>
))}
</div>

{/* Selected Filters Summary */}
{(filters.dietary_preferences.length > 0 || filters.max_cooking_time !== null) && (
<div className="bg-orange-50 border border-orange-200 rounded-lg p-4">
<h4 className="text-sm font-semibold text-orange-800 mb-2">Active Filters:</h4>
<div className="flex flex-wrap gap-2">
{filters.dietary_preferences.map((preference) => (
<span
key={preference}
className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-orange-100 text-orange-800"
>
{dietaryOptions.find(opt => opt.value === preference)?.label || preference}
</span>
<div className="flex flex-wrap items-center gap-6 text-[15px]">
<label className="flex items-center gap-2.5">
Max time
<select
value={filters.max_cooking_time ?? ''}
onChange={(e) => update({ max_cooking_time: e.target.value ? Number(e.target.value) : null })}
className={`h-10 px-3 ${fieldClass}`}
>
<option value="">Any</option>
{COOKING_TIMES.map((minutes) => (
<option key={minutes} value={minutes}>{minutes} min</option>
))}
{filters.max_cooking_time !== null && (
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-orange-100 text-orange-800">
⏱️ Max {filters.max_cooking_time} min
</span>
)}
</div>
</div>
)}
</div>
</select>
</label>

<label className="flex items-center gap-2.5">
<input
type="checkbox"
checked={filters.allow_external_ingredients}
onChange={(e) => update({ allow_external_ingredients: e.target.checked })}
className="size-5 accent-primary"
/>
Allow a few extras
<span className="text-sm text-muted">(adds a shopping list)</span>
</label>
</div>
</Card>
);
}
}
Loading
Loading