From 2f70e41bc4a9f89e7e6de551f2d76c48b3801e6e Mon Sep 17 00:00:00 2001 From: Kristoff Lalicki <32229646+klalicki@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:40:41 -0500 Subject: [PATCH] adds wrapper to RecipeViewer to display placeholder if recipe isn't loaded --- src/App.tsx | 6 +- src/components/RecipeViewer/RecipeViewer.tsx | 65 ++++++++++--------- .../RecipeViewerWrapper.tsx | 8 +++ src/index.tsx | 1 - 4 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 src/components/RecipeViewerWrapper/RecipeViewerWrapper.tsx diff --git a/src/App.tsx b/src/App.tsx index e96d0fb..2f4c83a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { FileLoader } from "./components/FileLoader/FileLoader"; -import { RecipeViewer } from "./components/RecipeViewer/RecipeViewer"; +import { RecipeViewerWrapper } from "./components/RecipeViewerWrapper/RecipeViewerWrapper"; // import { TargetScaleSetter } from "./components/TargetScaleSetter/TargetScaleSetter"; import { ScalerWrapper } from "./context/ScalerContext"; import "@mantine/core/styles.css"; @@ -13,8 +13,8 @@ const App = () => {

Bakers Mode

-
- +
+
diff --git a/src/components/RecipeViewer/RecipeViewer.tsx b/src/components/RecipeViewer/RecipeViewer.tsx index f646bdf..2b37084 100644 --- a/src/components/RecipeViewer/RecipeViewer.tsx +++ b/src/components/RecipeViewer/RecipeViewer.tsx @@ -4,38 +4,45 @@ import { RecipeStepDisplay } from "../RecipeStepDisplay/RecipeStepDisplay"; import { TargetScaleSetter } from "../TargetScaleSetter/TargetScaleSetter"; export const RecipeViewer = () => { - const { scaledRecipe, ingredientList } = useContext( + const { scaledRecipe, ingredientList, isRecipeLoaded } = useContext( ScalerContext ) as ScalerContextType; const stepCount = scaledRecipe.steps.length; - return ( -
-

{scaledRecipe.title}

-

{scaledRecipe.description}

- -

Steps

+ if (isRecipeLoaded) { + return ( +
+

{scaledRecipe.title}

+

{scaledRecipe.description}

+ +

Steps

-
    - {scaledRecipe.steps.map((step, index) => { - return ( -
  1. - -
  2. - ); - })} -
-

Cooking Notes

-
    - {scaledRecipe.cookingNotes.map((item) => { - return
  • {item}
  • ; - })} -
-
- ); +
    + {scaledRecipe.steps.map((step, index) => { + return ( +
  1. + +
  2. + ); + })} +
+

Cooking Notes

+
    + {scaledRecipe.cookingNotes.map((item) => { + return
  • {item}
  • ; + })} +
+
+ ); + } else { + return
Load a recipe
; + } }; diff --git a/src/components/RecipeViewerWrapper/RecipeViewerWrapper.tsx b/src/components/RecipeViewerWrapper/RecipeViewerWrapper.tsx new file mode 100644 index 0000000..a4a4265 --- /dev/null +++ b/src/components/RecipeViewerWrapper/RecipeViewerWrapper.tsx @@ -0,0 +1,8 @@ +import { useContext } from "react"; +import { ScalerContext, ScalerContextType } from "../../context/ScalerContext"; +import { RecipeViewer } from "../RecipeViewer/RecipeViewer"; +// RecipeViewerWrapper: a component that displays the recipe viewer if a recipe is loaded. If not it displays placeholder element +export const RecipeViewerWrapper = () => { + const { isRecipeLoaded } = useContext(ScalerContext) as ScalerContextType; + return isRecipeLoaded ? :
Recipe not loaded?
; +}; diff --git a/src/index.tsx b/src/index.tsx index e6a0350..e91ad13 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -10,7 +10,6 @@ const root = ReactDOM.createRoot( root.render( - {" "}