From 984e10682b9e551aed293ea3577f63be5bd0b54a Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Fri, 5 Dec 2025 10:38:04 +0200 Subject: [PATCH] Fix the slider --- frontend/src/App.jsx | 8 ++++-- frontend/src/components/RecipeSearchList.jsx | 26 ++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 18bfbad..10e6a3b 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -77,8 +77,11 @@ function App() { } // Filter by prep time - if (filterMaxTime && recipe.time_minutes > parseInt(filterMaxTime)) { - return false; + if (filterMaxTime) { + const maxTime = parseInt(filterMaxTime, 10); + if (recipe.time_minutes > maxTime) { + return false; + } } // Filter by tags @@ -207,6 +210,7 @@ function App() {
recipe.tags || [])) + new Set(allRecipes.flatMap((recipe) => recipe.tags || [])) ).sort(); - // Extract unique meal types from recipes - const mealTypes = Array.from(new Set(recipes.map((r) => r.meal_type))).sort(); + // Extract unique meal types from ALL recipes (not filtered) + const mealTypes = Array.from(new Set(allRecipes.map((r) => r.meal_type))).sort(); - // Extract max time for slider - const maxTimeInRecipes = Math.max(...recipes.map((r) => r.time_minutes), 0); + // Extract max time for slider from ALL recipes (not filtered) - add 10 to make it comfortable to select max time recipes + const maxTimeInRecipes = Math.max(...allRecipes.map((r) => r.time_minutes), 0); + const sliderMax = maxTimeInRecipes > 0 ? maxTimeInRecipes + 10 : 70; const handleTagToggle = (tag) => { if (filterTags.includes(tag)) { @@ -109,20 +111,24 @@ function RecipeSearchList({ {maxTimeInRecipes > 0 && (
onMaxTimeChange(e.target.value === "0" ? "" : e.target.value)} + onChange={(e) => { + const val = parseInt(e.target.value, 10); + onMaxTimeChange(val === 0 ? "" : String(val)); + }} className="time-slider" />
0 - {maxTimeInRecipes} + {sliderMax}