image null check

This commit is contained in:
Roland Schneider 2025-04-25 23:27:57 +02:00
parent 248a80727a
commit 477286fe45
9 changed files with 13 additions and 10 deletions

View File

@ -2,7 +2,7 @@ import { dirname } from "path";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc"; import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta?.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
const compat = new FlatCompat({ const compat = new FlatCompat({

View File

@ -8,6 +8,9 @@ class StrapiClient{
constructor(private strapiUrl: string = "http://localhost:1337") { constructor(private strapiUrl: string = "http://localhost:1337") {
} }
public getImageUrl(imagePath: string){ public getImageUrl(imagePath: string){
if ( !imagePath ){
return "dummy.png"
}
return '/image/'+ imagePath; return '/image/'+ imagePath;
} }
public async httpGet(path: string){ public async httpGet(path: string){

View File

@ -16,7 +16,7 @@ const AboutUsComponent = ( {data: {title,header,description,content,buttonText,b
<div className="row"> <div className="row">
<div className="col-lg-7 col-md-7 col-sm-12 col-xs-12"> <div className="col-lg-7 col-md-7 col-sm-12 col-xs-12">
<div className="aboutus_image"> <div className="aboutus_image">
<figure className="mb-0"><YogaImageComponent src={strapiApi.getImageUrl(fileImage.url)} alt="" className="img-fluid"/></figure> <figure className="mb-0"><YogaImageComponent src={strapiApi.getImageUrl(fileImage?.url)} alt="" className="img-fluid"/></figure>
</div> </div>
<figure className="aboutus_top_shape left_shape mb-0"> <figure className="aboutus_top_shape left_shape mb-0">
<YogaImageComponent src="/assets/images/aboutus_top_shape.png" alt="" className="img-fluid"/> <YogaImageComponent src="/assets/images/aboutus_top_shape.png" alt="" className="img-fluid"/>

View File

@ -14,7 +14,7 @@ const BlogSinglePostComponent = ({post: {header,teaserImage,tags,documentId} }:
<div className="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div className="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div className="blog_posts_image position-relative"> <div className="blog_posts_image position-relative">
<figure className="mb-0"> <figure className="mb-0">
<YogaImageComponent src={strapiApi.getImageUrl( teaserFile.url ) } alt="" <YogaImageComponent src={strapiApi.getImageUrl( teaserFile?.url ) } alt=""
className="img-fluid"/> className="img-fluid"/>
</figure> </figure>
<div className="blog_posts_image_content"> <div className="blog_posts_image_content">

View File

@ -16,7 +16,7 @@ const FeedbackComponent = ({active,config: {customerName, feedback, customerImag
<div className="testimonial_content"> <div className="testimonial_content">
<i className="fa-solid fa-quote-left"></i> <i className="fa-solid fa-quote-left"></i>
<p className="testimonial_paragraph">{feedback}</p> <p className="testimonial_paragraph">{feedback}</p>
<figure><YogaImageComponent src={strapiApi.getImageUrl(imageFile.url)} alt="" <figure><YogaImageComponent src={strapiApi.getImageUrl(imageFile?.url)} alt=""
className="img-fluid"/></figure> className="img-fluid"/></figure>
<p className="testimonial_person_name">{customerName}</p> <p className="testimonial_person_name">{customerName}</p>
<span>{customerDescription}</span> <span>{customerDescription}</span>

View File

@ -15,7 +15,7 @@ const OurServiceItemComponent = ({config: {header,description,image}}: Props) =>
<div className="services_box_content"> <div className="services_box_content">
<div className="services_box_upper_portion"> <div className="services_box_upper_portion">
<figure className="mb-0"> <figure className="mb-0">
<YogaImageComponent src={strapiApi.getImageUrl(imageFile.url)} alt="" className="img-fluid"/> <YogaImageComponent src={strapiApi.getImageUrl(imageFile?.url)} alt="" className="img-fluid"/>
</figure> </figure>
</div> </div>
<div className="services_box_lower_portion"> <div className="services_box_lower_portion">

View File

@ -11,17 +11,17 @@ export function PriceItemComponent({config: {header,option1,option2,price,icon,
// there are some issues with the strapi generated types // there are some issues with the strapi generated types
const iconFile: StrapiFile = icon as StrapiFile; const iconFile: StrapiFile = icon as StrapiFile;
const imageFile: StrapiFile = image as StrapiFile; const imageFile: StrapiFile = image as StrapiFile;
console.info("image:",strapiApi.getImageUrl(imageFile.url)); console.info("image:",strapiApi.getImageUrl(imageFile?.url));
return ( return (
<div className="col-lg-4 col-md-4 col-sm-6 col-xs-12"> <div className="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div className="pricing_plans_box_content"> <div className="pricing_plans_box_content">
<div className="pricing_plans_box_upper_portion"> <div className="pricing_plans_box_upper_portion">
<figure className="pricing_plans_image mb-0"> <figure className="pricing_plans_image mb-0">
<YogaImageComponent src={strapiApi.getImageUrl(imageFile.url)} alt="" className="img-fluid"/> <YogaImageComponent src={strapiApi.getImageUrl(imageFile?.url)} alt="" className="img-fluid"/>
</figure> </figure>
<div className="pricing_plans_box_image_content"> <div className="pricing_plans_box_image_content">
<figure className="mb-0"> <figure className="mb-0">
<YogaImageComponent src={strapiApi.getImageUrl(iconFile.url)} alt="" <YogaImageComponent src={strapiApi.getImageUrl(iconFile?.url)} alt=""
className="img-fluid"/> className="img-fluid"/>
</figure> </figure>
</div> </div>

View File

@ -11,7 +11,7 @@ export default function TextWithRightImage ({config: {
}}: Props){ }}: Props){
const strapiFile = image as StrapiFile; const strapiFile = image as StrapiFile;
const imageUrl = strapiApi.getImageUrl(strapiFile.url) const imageUrl = strapiApi.getImageUrl(strapiFile?.url)
return ( return (
<section className="mission_section"> <section className="mission_section">

View File

@ -12,7 +12,7 @@ export default function TextWithLeftImage ({config: {
}}: Props){ }}: Props){
const strapiFile = image as StrapiFile; const strapiFile = image as StrapiFile;
const imageUrl = strapiApi.getImageUrl(strapiFile.url) const imageUrl = strapiApi.getImageUrl(strapiFile?.url);
return ( return (