From 2da4c0aa1260b5fd9731486432adb109831933e3 Mon Sep 17 00:00:00 2001 From: fred <> Date: Thu, 7 Aug 2025 10:36:07 -0700 Subject: [PATCH 1/2] display hrs and minutes --- .../src/components/CookbookRecipeTile.tsx | 3 ++- frontend/src/components/TimeDisplay.tsx | 25 +++++++++++++++++++ frontend/src/pages/RecipePage.tsx | 8 +++--- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 frontend/src/components/TimeDisplay.tsx diff --git a/frontend/src/components/CookbookRecipeTile.tsx b/frontend/src/components/CookbookRecipeTile.tsx index c090f26..31a73c3 100644 --- a/frontend/src/components/CookbookRecipeTile.tsx +++ b/frontend/src/components/CookbookRecipeTile.tsx @@ -1,6 +1,7 @@ import { type RecipeSmall } from "../types/Recipe" import { Link } from 'react-router-dom'; import StarRating from '../components/StarRating.tsx' +import TimeDisplay from "../components/TimeDisplay.tsx" function CookbookRecipeTile({ recipe }: { recipe: RecipeSmall }) { @@ -13,7 +14,7 @@ function CookbookRecipeTile({ recipe }: { recipe: RecipeSmall }) {
- ⏰ {recipe.prep_minutes + recipe.cook_minutes} min + ⏰ { }} />
diff --git a/frontend/src/components/TimeDisplay.tsx b/frontend/src/components/TimeDisplay.tsx new file mode 100644 index 0000000..34c749e --- /dev/null +++ b/frontend/src/components/TimeDisplay.tsx @@ -0,0 +1,25 @@ +interface TimeDisplayProps { + minutes: number; +} + +const TimeDisplay = ({ minutes }: TimeDisplayProps) => { + let displayText: string; + + if (minutes < 60) { + displayText = `${minutes} min`; + } else { + const hours = Math.floor(minutes / 60); + const remainingMinutes = minutes % 60; + if (hours > 0 && remainingMinutes > 0) { + displayText = `${hours} hr${hours !== 1 ? 's' : ''} ${remainingMinutes} min`; + } else if (hours > 0) { + displayText = `${hours} hr${hours !== 1 ? 's' : ''}`; + } else { + displayText = `${remainingMinutes} min`; + } + } + + return <>{displayText}; +}; + +export default TimeDisplay; diff --git a/frontend/src/pages/RecipePage.tsx b/frontend/src/pages/RecipePage.tsx index dbc92de..bfef52c 100644 --- a/frontend/src/pages/RecipePage.tsx +++ b/frontend/src/pages/RecipePage.tsx @@ -1,11 +1,11 @@ import { useParams, useNavigate, Link } from "react-router-dom"; import { useState, useEffect } from "react"; -import { getRecipeById, deleteRecipe } from "../services/frontendApi.js"; +import { getRecipeById, deleteRecipe, setDBStars } from "../services/frontendApi.js"; import { type Recipe, type Ingredient } from "../types/Recipe" -import StarRating from "../components/StarRating.tsx" -import { setDBStars } from "../services/frontendApi.js"; import Modal from '../components/Modal.tsx' import DemoModal from '../components/DemoModal.tsx' +import StarRating from "../components/StarRating.tsx" +import TimeDisplay from '../components/TimeDisplay.tsx' function RecipePage() { const [recipe, setRecipe] = useState({ @@ -106,7 +106,7 @@ function RecipePage() {

{recipe.details.name}

{recipe.details.cuisine}

-

prep: {recipe.details.prep_minutes} min | cook: {recipe.details.cook_minutes} min

+

prep: | cook:

From fdaf4cff1fa8770e91f3a7fbe7f9bf1297077040 Mon Sep 17 00:00:00 2001 From: fred <> Date: Thu, 7 Aug 2025 11:57:11 -0700 Subject: [PATCH 2/2] fix mobile tabs --- frontend/src/components/DemoModal.tsx | 2 +- frontend/src/components/Modal.tsx | 2 +- frontend/src/components/RecipeBookTabs.tsx | 32 ++++++++++++---------- frontend/src/pages/RecipePage.tsx | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/DemoModal.tsx b/frontend/src/components/DemoModal.tsx index c3b1d0f..de4f6e9 100644 --- a/frontend/src/components/DemoModal.tsx +++ b/frontend/src/components/DemoModal.tsx @@ -10,7 +10,7 @@ const DemoModal = ({ isOpen, onClose, closeModal }: DemoModalProps) => { if (!isOpen) return null; return ( -
+
e.stopPropagation()}>

Thanks for checking out my app! Database write operations are disabled in demo mode.

diff --git a/frontend/src/components/Modal.tsx b/frontend/src/components/Modal.tsx index 8985471..5ee8453 100644 --- a/frontend/src/components/Modal.tsx +++ b/frontend/src/components/Modal.tsx @@ -10,7 +10,7 @@ const Modal = ({ isOpen, onClose, message, confirmAction, cancelAction }: ModalP if (!isOpen) return null; return ( -
+
e.stopPropagation()}>
{message} diff --git a/frontend/src/components/RecipeBookTabs.tsx b/frontend/src/components/RecipeBookTabs.tsx index 890e6fb..b00ba02 100644 --- a/frontend/src/components/RecipeBookTabs.tsx +++ b/frontend/src/components/RecipeBookTabs.tsx @@ -35,9 +35,9 @@ const RecipeBookTabs = () => { const tabs = [ - { id: '/', label: 'All Recipes', icon: '📚' }, + { id: '/', label: 'Cookbook', icon: '📚' }, { id: `/recipe/${lastViewedRecipeId}`, label: 'Recipe', icon: '🥗' }, - { id: '/add-recipe', label: 'Add Recipe', icon: '➕' }, + { id: '/add-recipe', label: 'Add', icon: '➕' }, { id: '/about', label: 'About', icon: '🍽️' }, ]; @@ -55,7 +55,7 @@ const RecipeBookTabs = () => { key={tab.id} to={tab.id} className={` - relative px-6 py-3 rounded-t-lg font-bold text-sm transform text-amber-800 + relative px-3 py-2 md:px-6 md:py-3 rounded-t-lg font-bold text-sm transform text-amber-800 ${isActive ? 'bg-amber-100 scale-105 z-10 border-t-2 border-amber-200' : 'bg-amber-200 hover:bg-amber-100 hover:text-amber-700 hover:scale-102 shadow-sm' @@ -64,21 +64,23 @@ const RecipeBookTabs = () => { ${isActive ? '' : ''} `} > -
- {tab.icon} +
+ {tab.icon} {tab.label}
- {isActive && ( - <> -
-
-
-
-
-
- - )} + { + isActive && ( + <> +
+
+
+
+
+
+ + ) + } ); })} diff --git a/frontend/src/pages/RecipePage.tsx b/frontend/src/pages/RecipePage.tsx index bfef52c..f5c1aea 100644 --- a/frontend/src/pages/RecipePage.tsx +++ b/frontend/src/pages/RecipePage.tsx @@ -100,7 +100,7 @@ function RecipePage() { ) : (
-