diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index 99f7e43..9073048 100644 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -51,14 +51,14 @@ export function HomePage() { const handleRandomCook = async () => { try { const recipe = await fetchRandomRecipe(['mittag', 'abend', 'fruehstueck']) - if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random`) + if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random&type=cook`) } catch { /* no recipes */ } } const handleRandomBake = async () => { try { const recipe = await fetchRandomRecipe(['backen', 'torten', 'desserts']) - if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random`) + if (recipe?.slug) navigate(`/recipe/${recipe.slug}?from=random&type=bake`) } catch { /* no recipes */ } } diff --git a/frontend/src/pages/RecipePage.tsx b/frontend/src/pages/RecipePage.tsx index 1c804f2..29dedf4 100644 --- a/frontend/src/pages/RecipePage.tsx +++ b/frontend/src/pages/RecipePage.tsx @@ -19,20 +19,25 @@ export function RecipePage() { const navigate = useNavigate() const [searchParams] = useSearchParams() const fromRandom = searchParams.get('from') === 'random' + const randomType = searchParams.get('type') // 'cook' or 'bake' const qc = useQueryClient() const [servingScale, setServingScale] = useState(null) const [noteText, setNoteText] = useState('') const [rerolling, setRerolling] = useState(false) const [showIngredientPicker, setShowIngredientPicker] = useState(false) + const COOK_CATEGORIES = ['mittag', 'abend', 'fruehstueck'] + const BAKE_CATEGORIES = ['backen', 'torten', 'desserts'] + const handleReroll = useCallback(async () => { setRerolling(true) try { - const r = await fetchRandomRecipe() - if (r?.slug) navigate(`/recipe/${r.slug}?from=random`, { replace: true }) + const categories = randomType === 'bake' ? BAKE_CATEGORIES : randomType === 'cook' ? COOK_CATEGORIES : undefined + const r = await fetchRandomRecipe(categories) + if (r?.slug) navigate(`/recipe/${r.slug}?from=random${randomType ? `&type=${randomType}` : ''}`, { replace: true }) } catch { /* ignore */ } setRerolling(false) - }, [navigate]) + }, [navigate, randomType]) const { data: recipe, isLoading } = useQuery({ queryKey: ['recipe', slug],