From 477286fe451d6bad1c11f51dc5b52acb721122c8 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 25 Apr 2025 23:27:57 +0200 Subject: [PATCH] image null check --- yoga-app/eslint.config.mjs | 2 +- yoga-app/src/api/strapi/strapi-client.ts | 3 +++ yoga-app/src/components/about.us.component.tsx | 2 +- yoga-app/src/components/blog.single.post.component.tsx | 2 +- yoga-app/src/components/feedbackItemComponent.tsx | 2 +- yoga-app/src/components/our.services.item.component.tsx | 2 +- yoga-app/src/components/price.item.component.tsx | 6 +++--- yoga-app/src/components/text.with.right.image.component.tsx | 2 +- yoga-app/src/components/text.with.right.left.component.tsx | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/yoga-app/eslint.config.mjs b/yoga-app/eslint.config.mjs index 2b254dc..d047268 100644 --- a/yoga-app/eslint.config.mjs +++ b/yoga-app/eslint.config.mjs @@ -2,7 +2,7 @@ import { dirname } from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; -const __filename = fileURLToPath(import.meta.url); +const __filename = fileURLToPath(import.meta?.url); const __dirname = dirname(__filename); const compat = new FlatCompat({ diff --git a/yoga-app/src/api/strapi/strapi-client.ts b/yoga-app/src/api/strapi/strapi-client.ts index 2fb2e7e..9cf838a 100644 --- a/yoga-app/src/api/strapi/strapi-client.ts +++ b/yoga-app/src/api/strapi/strapi-client.ts @@ -8,6 +8,9 @@ class StrapiClient{ constructor(private strapiUrl: string = "http://localhost:1337") { } public getImageUrl(imagePath: string){ + if ( !imagePath ){ + return "dummy.png" + } return '/image/'+ imagePath; } public async httpGet(path: string){ diff --git a/yoga-app/src/components/about.us.component.tsx b/yoga-app/src/components/about.us.component.tsx index 38f7106..bd4e63b 100644 --- a/yoga-app/src/components/about.us.component.tsx +++ b/yoga-app/src/components/about.us.component.tsx @@ -16,7 +16,7 @@ const AboutUsComponent = ( {data: {title,header,description,content,buttonText,b
-
+
diff --git a/yoga-app/src/components/blog.single.post.component.tsx b/yoga-app/src/components/blog.single.post.component.tsx index d2a7d81..235a091 100644 --- a/yoga-app/src/components/blog.single.post.component.tsx +++ b/yoga-app/src/components/blog.single.post.component.tsx @@ -14,7 +14,7 @@ const BlogSinglePostComponent = ({post: {header,teaserImage,tags,documentId} }:
-
diff --git a/yoga-app/src/components/feedbackItemComponent.tsx b/yoga-app/src/components/feedbackItemComponent.tsx index 1ce77bd..c0bf4d4 100644 --- a/yoga-app/src/components/feedbackItemComponent.tsx +++ b/yoga-app/src/components/feedbackItemComponent.tsx @@ -16,7 +16,7 @@ const FeedbackComponent = ({active,config: {customerName, feedback, customerImag

“{feedback}”

-

{customerName}

{customerDescription} diff --git a/yoga-app/src/components/our.services.item.component.tsx b/yoga-app/src/components/our.services.item.component.tsx index 715e0db..3e1804f 100644 --- a/yoga-app/src/components/our.services.item.component.tsx +++ b/yoga-app/src/components/our.services.item.component.tsx @@ -15,7 +15,7 @@ const OurServiceItemComponent = ({config: {header,description,image}}: Props) =>
- +
diff --git a/yoga-app/src/components/price.item.component.tsx b/yoga-app/src/components/price.item.component.tsx index 05add9b..556d31a 100644 --- a/yoga-app/src/components/price.item.component.tsx +++ b/yoga-app/src/components/price.item.component.tsx @@ -11,17 +11,17 @@ export function PriceItemComponent({config: {header,option1,option2,price,icon, // there are some issues with the strapi generated types const iconFile: StrapiFile = icon as StrapiFile; const imageFile: StrapiFile = image as StrapiFile; - console.info("image:",strapiApi.getImageUrl(imageFile.url)); + console.info("image:",strapiApi.getImageUrl(imageFile?.url)); return (
- +
-
diff --git a/yoga-app/src/components/text.with.right.image.component.tsx b/yoga-app/src/components/text.with.right.image.component.tsx index b0e7555..9f4ee80 100644 --- a/yoga-app/src/components/text.with.right.image.component.tsx +++ b/yoga-app/src/components/text.with.right.image.component.tsx @@ -11,7 +11,7 @@ export default function TextWithRightImage ({config: { }}: Props){ const strapiFile = image as StrapiFile; - const imageUrl = strapiApi.getImageUrl(strapiFile.url) + const imageUrl = strapiApi.getImageUrl(strapiFile?.url) return (
diff --git a/yoga-app/src/components/text.with.right.left.component.tsx b/yoga-app/src/components/text.with.right.left.component.tsx index 23e691e..0688d56 100644 --- a/yoga-app/src/components/text.with.right.left.component.tsx +++ b/yoga-app/src/components/text.with.right.left.component.tsx @@ -12,7 +12,7 @@ export default function TextWithLeftImage ({config: { }}: Props){ const strapiFile = image as StrapiFile; - const imageUrl = strapiApi.getImageUrl(strapiFile.url) + const imageUrl = strapiApi.getImageUrl(strapiFile?.url); return (