feat: split random into 'Was koche ich?' + 'Was backe ich?'
- Two dice buttons on homepage - Cook: mittag, abend, fruehstueck categories - Bake: backen, torten, desserts categories - Backend: /api/recipes/random?categories=slug1,slug2 filter - Luna's feature request
This commit is contained in:
@@ -24,8 +24,9 @@ export function fetchRecipe(slug: string) {
|
||||
return apiFetch<Recipe>(`/recipes/${slug}`)
|
||||
}
|
||||
|
||||
export function fetchRandomRecipe() {
|
||||
return apiFetch<Recipe>('/recipes/random')
|
||||
export function fetchRandomRecipe(categories?: string[]) {
|
||||
const qs = categories ? `?categories=${categories.join(',')}` : ''
|
||||
return apiFetch<Recipe>(`/recipes/random${qs}`)
|
||||
}
|
||||
|
||||
export function searchRecipes(q: string) {
|
||||
|
||||
@@ -48,13 +48,18 @@ export function HomePage() {
|
||||
? recipes.filter(r => r.tags?.includes(activeTag))
|
||||
: recipes
|
||||
|
||||
const handleRandomRecipe = async () => {
|
||||
const handleRandomCook = async () => {
|
||||
try {
|
||||
const recipe = await fetchRandomRecipe()
|
||||
const recipe = await fetchRandomRecipe(['mittag', 'abend', 'fruehstueck'])
|
||||
if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random`)
|
||||
} catch {
|
||||
// no recipes
|
||||
}
|
||||
} catch { /* no recipes */ }
|
||||
}
|
||||
|
||||
const handleRandomBake = async () => {
|
||||
try {
|
||||
const recipe = await fetchRandomRecipe(['backen', 'torten', 'desserts'])
|
||||
if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random`)
|
||||
} catch { /* no recipes */ }
|
||||
}
|
||||
|
||||
const activeTags = (tags || []).filter(t => t.recipe_count > 0)
|
||||
@@ -80,15 +85,22 @@ export function HomePage() {
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Random Recipe Button */}
|
||||
{/* Random Recipe Buttons */}
|
||||
{totalCount > 1 && (
|
||||
<div className="px-4 pb-4">
|
||||
<div className="px-4 pb-4 flex gap-2">
|
||||
<button
|
||||
onClick={handleRandomRecipe}
|
||||
className="w-full bg-gradient-to-r from-primary to-secondary text-white px-4 py-3 rounded-2xl font-medium text-sm flex items-center justify-center gap-2 shadow-sm active:scale-[0.98] transition-transform min-h-[44px]"
|
||||
onClick={handleRandomCook}
|
||||
className="flex-1 bg-gradient-to-r from-primary to-secondary text-white px-3 py-3 rounded-2xl font-medium text-sm flex items-center justify-center gap-2 shadow-sm active:scale-[0.98] transition-transform min-h-[44px]"
|
||||
>
|
||||
<Dices size={18} />
|
||||
Was koche ich heute? 🎲
|
||||
<Dices size={16} />
|
||||
Was koche ich? 🥘
|
||||
</button>
|
||||
<button
|
||||
onClick={handleRandomBake}
|
||||
className="flex-1 bg-gradient-to-r from-secondary to-primary text-white px-3 py-3 rounded-2xl font-medium text-sm flex items-center justify-center gap-2 shadow-sm active:scale-[0.98] transition-transform min-h-[44px]"
|
||||
>
|
||||
<Dices size={16} />
|
||||
Was backe ich? 🎂
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user