Skip to content

Commit

Permalink
Product images add to Home page
Browse files Browse the repository at this point in the history
  • Loading branch information
mwlt68 committed Mar 11, 2023
1 parent c8fdb34 commit 9d45020
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/pages/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "../../utils/consts/NavigationConsts";
import { AdvancedSideBar } from "../../components/ui/side-bar/AdvancedSideBar";
import { UrlHelper } from "../../utils/helpers/UrlHelper";
import { ImageHelper } from "../../utils/helpers/ImageHelper";

export default function HomePage() {
const navigate = useNavigate();
Expand Down Expand Up @@ -109,20 +110,20 @@ export default function HomePage() {
}}
>
<Card>
<ProductCardMedia />
<ProductCardMedia product={props.product} />
<ProductCardContent product={props.product} />
<ProductCardAction productPrice={props.product.price} />
</Card>
</CardActionArea>
);
}

function ProductCardMedia() {
function ProductCardMedia(props: { product: ProductResultModel }) {
return (
<CardMedia
component="img"
height={styles.productImage.height}
image="https://img-lcwaikiki.mncdn.com/mnresize/1024/-/pim/productimages/20222/6012505/v1/l_20222-w2cg02z8-rfh-96-81-93-190_a.jpg"
image= {ImageHelper.Get( props.product.image)}
sx={styles.productCardImage}
/>
);
Expand Down
5 changes: 2 additions & 3 deletions src/pages/product/ProductPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NavigationConsts,
QueryParameterConsts,
} from "../../utils/consts/NavigationConsts";
import { ImageHelper } from "../../utils/helpers/ImageHelper";
import { styles } from "./ProductPageStyle";

export default function ProductPage() {
Expand Down Expand Up @@ -171,9 +172,7 @@ export default function ProductPage() {
const getImageUrl = (): string | undefined => {
if (pickedImage != null) return URL.createObjectURL(pickedImage);
else
return product.image != null && product.image.length > 0
? "data:image/png;base64," + product.image
: undefined;
return ImageHelper.Get(product.image);
};

return (
Expand Down
7 changes: 7 additions & 0 deletions src/utils/helpers/ImageHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class ImageHelper {
static Get(image: undefined | []) {
return image != null && image.length > 0
? "data:image/png;base64," + image
: undefined;
}
}

0 comments on commit 9d45020

Please sign in to comment.