diff --git a/frontend/index.html b/frontend/index.html index eac963c..472f4d4 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -9,6 +9,14 @@ name="description" content="Turn the ingredients you already have into a recipe, powered by Google Gemini." /> + +
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 1ae00dc..ba5f953 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -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([]); - const [filters, setFilters] = useState({ - dietary_preferences: [] as string[], - max_cooking_time: null as number | null, - allow_external_ingredients: false - }); + const [filters, setFilters] = useState(DEFAULT_FILTERS); const [recipe, setRecipe] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); @@ -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 ( -
-
- {/* Header */} -
-

- 🍳 Cookable -

-

- Enter your available ingredients and get AI-powered recipe suggestions -

-
- - {/* Main Content */} -
- {/* Step 1: Ingredient Input */} -
-

- 1️⃣ Enter Your Ingredients -

- +
+
+
+
+

+ Cookable +

+

Your ingredients in. A recipe out.

+ +
- {/* Step 2: Filter Options */} -
-

- 2️⃣ Optional Filters -

- -
- - {/* Step 3: Get Recipe Button */} -
- -
+ + - {/* Error Display */} - {error && ( -
- {error} -
- )} + - {/* Step 4: Recipe Display */} - {recipe && ( -
-

- 3️⃣ Your Recipe -

- -
- )} + {error && ( +
+ {error} +
+ )} - {/* Reset Button */} - {recipe && ( -
- -
- )} -
-
+ {recipe && ( + <> + + + + )} +
); } diff --git a/frontend/src/components/FilterOptions.tsx b/frontend/src/components/FilterOptions.tsx index e22ed28..09ad951 100644 --- a/frontend/src/components/FilterOptions.tsx +++ b/frontend/src/components/FilterOptions.tsx @@ -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) => 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 ( -
- {/* External Ingredients Toggle */} -
- -

- If enabled, we'll suggest recipes that might require a few extra items, and we'll provide a shopping list for them. -

-
- - {/* Dietary Preferences */} -
-

Dietary Preferences:

-
- {dietaryOptions.map((option) => ( - - ))} -
-
+ + - {/* Cooking Time */} -
-

Maximum Cooking Time:

-
- - {cookingTimeOptions.map((option) => ( - - ))} -
+ {label} + + ))}
- {/* Selected Filters Summary */} - {(filters.dietary_preferences.length > 0 || filters.max_cooking_time !== null) && ( -
-

Active Filters:

-
- {filters.dietary_preferences.map((preference) => ( - - {dietaryOptions.find(opt => opt.value === preference)?.label || preference} - +
+ + + +
+ ); -} \ No newline at end of file +} diff --git a/frontend/src/components/IngredientInput.tsx b/frontend/src/components/IngredientInput.tsx index a63e941..1c5c858 100644 --- a/frontend/src/components/IngredientInput.tsx +++ b/frontend/src/components/IngredientInput.tsx @@ -1,4 +1,10 @@ -import { useState } from 'react'; +import { useState, type FormEvent } from 'react'; +import { Button } from '@/components/ui/Button'; +import { Card, StepHeading } from '@/components/ui/Card'; +import { RemovableChip } from '@/components/ui/Chip'; +import { fieldClass } from '@/components/ui/field'; + +const QUICK_ADD = ['onion', 'garlic', 'tomato', 'chicken', 'rice', 'pasta', 'egg', 'cheese']; interface IngredientInputProps { ingredients: string[]; @@ -8,94 +14,66 @@ interface IngredientInputProps { export default function IngredientInput({ ingredients, onIngredientsChange }: IngredientInputProps) { const [inputValue, setInputValue] = useState(''); - const handleAddIngredient = () => { - const trimmedValue = inputValue.trim(); - if (trimmedValue && !ingredients.includes(trimmedValue.toLowerCase())) { - onIngredientsChange([...ingredients, trimmedValue.toLowerCase()]); - setInputValue(''); + const add = (name: string) => { + const ingredient = name.trim().toLowerCase(); + if (ingredient && !ingredients.includes(ingredient)) { + onIngredientsChange([...ingredients, ingredient]); } }; - const handleRemoveIngredient = (ingredient: string) => { - const newIngredients = ingredients.filter((i) => i !== ingredient); - onIngredientsChange(newIngredients); + const remove = (ingredient: string) => { + onIngredientsChange(ingredients.filter((i) => i !== ingredient)); }; - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { - handleAddIngredient(); - } + const handleSubmit = (e: FormEvent) => { + e.preventDefault(); + add(inputValue); + setInputValue(''); }; return ( -
- {/* Input Field */} -
+ + + +
+ setInputValue(e.target.value)} - onKeyDown={handleKeyDown} - aria-label="Ingredient" - placeholder="Enter an ingredient (e.g., chicken, tomato, rice)" - className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-orange-500 focus:border-transparent" + placeholder="Add an ingredient, e.g. chickpeas" + className={`h-13 min-w-0 flex-1 px-4.5 text-base ${fieldClass}`} /> - -
+ + - {/* Ingredients List */} {ingredients.length > 0 && ( -
-

Your Ingredients:

-
- {ingredients.map((ingredient) => ( -
- {ingredient} - -
- ))} -
+
+ {ingredients.map((ingredient) => ( + remove(ingredient)} /> + ))}
)} - {/* Quick Add Suggestions */} -
-

Quick Add Common Ingredients:

+
+ Quick add
- {['onion', 'garlic', 'tomato', 'chicken', 'rice', 'pasta', 'egg', 'cheese'].map((suggestion) => ( + {QUICK_ADD.map((name) => ( ))}
-
+ ); -} \ No newline at end of file +} diff --git a/frontend/src/components/RecipeDisplay.tsx b/frontend/src/components/RecipeDisplay.tsx index a6c51ab..38f40ba 100644 --- a/frontend/src/components/RecipeDisplay.tsx +++ b/frontend/src/components/RecipeDisplay.tsx @@ -1,131 +1,53 @@ -import { Recipe } from '@/types/recipe'; +import { Card } from '@/components/ui/Card'; +import { Tag } from '@/components/ui/Chip'; +import type { Recipe } from '@/types/recipe'; interface RecipeDisplayProps { recipe: Recipe; } export default function RecipeDisplay({ recipe }: RecipeDisplayProps) { - const getDifficultyColor = (difficulty: string) => { - switch (difficulty.toLowerCase()) { - case 'easy': - return 'bg-green-100 text-green-800'; - case 'medium': - return 'bg-yellow-100 text-yellow-800'; - case 'hard': - return 'bg-red-100 text-red-800'; - default: - return 'bg-gray-100 text-gray-800'; - } - }; + const shoppingList = recipe.shopping_list ?? []; return ( -
- {/* Recipe Header */} -
-

{recipe.title}

-
- - ⏱️ {recipe.cooking_time} minutes - - - {recipe.difficulty} - - - 👥 {recipe.servings} servings - -
-
- - {/* Recipe Tags */} - {recipe.tags.length > 0 && ( -
- {recipe.tags.map((tag, index) => ( - - {tag} - + +
+

{recipe.title}

+
+ {recipe.cooking_time} min + {recipe.difficulty} + Serves {recipe.servings} + {recipe.tags.map((tag) => ( + {tag} ))}
- )} - - {/* Ingredients */} -
-

- 🥘 Ingredients -

-
    - {recipe.ingredients.map((ingredient, index) => ( -
  • - - {ingredient} -
  • - ))} -
-
- - {/* Instructions */} -
-

- 📝 Instructions -

-
    - {recipe.instructions.map((instruction, index) => ( -
  1. - - {index + 1} - - {instruction} -
  2. - ))} -
- {/* Shopping List */} - {recipe.shopping_list && recipe.shopping_list.length > 0 && ( -
-

- 🛒 Shopping List -

-
    - {recipe.shopping_list.map((item, index) => ( -
  • - - {item} -
  • +
    +
    +

    Ingredients

    +
      + {recipe.ingredients.map((ingredient, i) => ( +
    • {ingredient}
    • ))}
    - )} - - {/* Recipe Summary */} -
    -

    Recipe Summary

    -
    -
    -
    {recipe.cooking_time}
    -
    Minutes
    -
    -
    -
    {recipe.servings}
    -
    Servings
    -
    -
    -
    {recipe.ingredients.length}
    -
    Ingredients
    -
    +
    +

    Steps

    +
      + {recipe.instructions.map((step, i) => ( +
    1. {step}
    2. + ))} +
    -
    + + {shoppingList.length > 0 && ( +
    + Shopping list + {shoppingList.join(', ')} +
    + )} + ); -} \ No newline at end of file +} diff --git a/frontend/src/components/ThemeToggle.tsx b/frontend/src/components/ThemeToggle.tsx new file mode 100644 index 0000000..a1230b8 --- /dev/null +++ b/frontend/src/components/ThemeToggle.tsx @@ -0,0 +1,29 @@ +import { useTheme } from '@/hooks/useTheme'; + +export default function ThemeToggle() { + const { theme, toggle } = useTheme(); + const next = theme === 'dark' ? 'light' : 'dark'; + + return ( + + ); +} diff --git a/frontend/src/components/ui/Button.tsx b/frontend/src/components/ui/Button.tsx new file mode 100644 index 0000000..67e73dc --- /dev/null +++ b/frontend/src/components/ui/Button.tsx @@ -0,0 +1,23 @@ +import type { ButtonHTMLAttributes } from 'react'; + +type Variant = 'primary' | 'strong' | 'outline'; + +const variants: Record = { + primary: 'bg-primary text-on-primary', + strong: 'bg-strong text-on-strong', + outline: 'border-2 border-field-line text-fg hover:bg-surface', +}; + +interface ButtonProps extends ButtonHTMLAttributes { + variant?: Variant; +} + +export function Button({ variant = 'strong', className = '', type = 'button', ...props }: ButtonProps) { + return ( + + ); +} + +interface RemovableChipProps { + label: string; + onRemove: () => void; +} + +/** A selected item with a remove button, e.g. an added ingredient. */ +export function RemovableChip({ label, onRemove }: RemovableChipProps) { + return ( + + {label} + + + ); +} + +interface TagProps { + children: ReactNode; + accent?: boolean; +} + +/** A small read-only label, e.g. a recipe's cooking time. */ +export function Tag({ children, accent = false }: TagProps) { + const look = accent ? 'bg-primary text-on-primary' : 'bg-tag text-on-tag'; + return {children}; +} diff --git a/frontend/src/components/ui/field.ts b/frontend/src/components/ui/field.ts new file mode 100644 index 0000000..a8221b9 --- /dev/null +++ b/frontend/src/components/ui/field.ts @@ -0,0 +1,3 @@ +// Shared look for text inputs and selects +export const fieldClass = + 'rounded-xl border-2 border-field-line bg-field text-fg placeholder:text-muted focus:border-primary focus:outline-none'; diff --git a/frontend/src/hooks/useTheme.ts b/frontend/src/hooks/useTheme.ts new file mode 100644 index 0000000..d2ec958 --- /dev/null +++ b/frontend/src/hooks/useTheme.ts @@ -0,0 +1,53 @@ +import { useEffect, useState } from 'react'; + +export type Theme = 'light' | 'dark'; + +const STORAGE_KEY = 'theme'; +const systemQuery = window.matchMedia('(prefers-color-scheme: dark)'); + +function savedTheme(): Theme | null { + try { + const value = localStorage.getItem(STORAGE_KEY); + return value === 'light' || value === 'dark' ? value : null; + } catch { + return null; + } +} + +function applyTheme(theme: Theme) { + document.documentElement.classList.toggle('dark', theme === 'dark'); +} + +/** + * Light/dark theme. Follows the OS setting until the user picks one with + * toggle(); the inline script in index.html applies it before first paint. + */ +export function useTheme() { + const [theme, setTheme] = useState( + () => savedTheme() ?? (systemQuery.matches ? 'dark' : 'light'), + ); + + useEffect(() => { + applyTheme(theme); + }, [theme]); + + useEffect(() => { + const onSystemChange = (e: MediaQueryListEvent) => { + if (!savedTheme()) setTheme(e.matches ? 'dark' : 'light'); + }; + systemQuery.addEventListener('change', onSystemChange); + return () => systemQuery.removeEventListener('change', onSystemChange); + }, []); + + const toggle = () => { + const next = theme === 'dark' ? 'light' : 'dark'; + try { + localStorage.setItem(STORAGE_KEY, next); + } catch { + // Storage can be unavailable (e.g. private mode); the theme still switches + } + setTheme(next); + }; + + return { theme, toggle }; +} diff --git a/frontend/src/index.css b/frontend/src/index.css index 2325ed8..4b513d4 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1,10 +1,76 @@ @import "tailwindcss"; -@theme { +/* + * Color tokens. Components only use the semantic names below (bg-surface, + * text-muted, ...), so each theme is defined once here. + */ +:root { + color-scheme: light; + --bg: #fef3e2; + --surface: #fffaf3; + --line: #f2c478; + --field: #ffffff; + --field-line: #ebc07e; + --fg: #2a1a0e; + --muted: #6b5440; + --accent: #c27000; + --accent-text: #8f5a0e; + --primary: #f4ae52; + --on-primary: #2a1a0e; + --strong: #2a1a0e; + --on-strong: #fef3e2; + --selected: #f4ae52; + --on-selected: #2a1a0e; + --tag: #2a1a0e; + --on-tag: #fef3e2; + --danger: #b42318; +} + +:root.dark { + color-scheme: dark; + --bg: #2a1a0e; + --surface: #3a2617; + --line: #3a2617; + --field: #2a1a0e; + --field-line: #5a3f28; + --fg: #fef3e2; + --muted: #c9b29a; + --accent: #f4ae52; + --accent-text: #f4ae52; + --primary: #f4ae52; + --on-primary: #2a1a0e; + --strong: #f4ae52; + --on-strong: #2a1a0e; + --selected: #fef3e2; + --on-selected: #2a1a0e; + --tag: #5a3f28; + --on-tag: #fef3e2; + --danger: #fda29b; +} + +@theme inline { --font-sans: "Geist Variable", ui-sans-serif, system-ui, sans-serif; + + --color-bg: var(--bg); + --color-surface: var(--surface); + --color-line: var(--line); + --color-field: var(--field); + --color-field-line: var(--field-line); + --color-fg: var(--fg); + --color-muted: var(--muted); + --color-accent: var(--accent); + --color-accent-text: var(--accent-text); + --color-primary: var(--primary); + --color-on-primary: var(--on-primary); + --color-strong: var(--strong); + --color-on-strong: var(--on-strong); + --color-selected: var(--selected); + --color-on-selected: var(--on-selected); + --color-tag: var(--tag); + --color-on-tag: var(--on-tag); + --color-danger: var(--danger); } body { - background: #fff7ed; - color: #171717; + @apply bg-bg text-fg; } diff --git a/frontend/src/types/recipe.ts b/frontend/src/types/recipe.ts index d95928c..30f4c11 100644 --- a/frontend/src/types/recipe.ts +++ b/frontend/src/types/recipe.ts @@ -19,4 +19,5 @@ export interface IngredientRequest { export interface FilterOptions { dietary_preferences: string[]; max_cooking_time: number | null; + allow_external_ingredients: boolean; }