Added default image and dynamic image load from backend.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 MiB |
BIN
01-frontend/src/assets/default.jpg
Normal file
BIN
01-frontend/src/assets/default.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
@@ -5,7 +5,6 @@ import Item from "../../components/Item";
|
|||||||
import { useBasket } from "../BasketProvider";
|
import { useBasket } from "../BasketProvider";
|
||||||
import "../helper.css";
|
import "../helper.css";
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import HTWImage from '../../assets/HTW.jpg';
|
|
||||||
|
|
||||||
export default function ItemCard({ item }: { item: Item }) {
|
export default function ItemCard({ item }: { item: Item }) {
|
||||||
|
|
||||||
@@ -22,6 +21,8 @@ export default function ItemCard({ item }: { item: Item }) {
|
|||||||
navigate(`/product/${item.id}`, { state: { item } });
|
navigate(`/product/${item.id}`, { state: { item } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imageUrl = `http://localhost:8085/image?articleId=${item.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper elevation={4}>
|
<Paper elevation={4}>
|
||||||
<Card>
|
<Card>
|
||||||
@@ -29,8 +30,11 @@ export default function ItemCard({ item }: { item: Item }) {
|
|||||||
<CardMedia
|
<CardMedia
|
||||||
component="img"
|
component="img"
|
||||||
height="140"
|
height="140"
|
||||||
image={HTWImage}
|
image={imageUrl}
|
||||||
alt={item.name}
|
alt={item.name}
|
||||||
|
onError={(event) => {
|
||||||
|
event.currentTarget.src = "/src/assets/default.jpg"; // Standardbild setzen
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography gutterBottom variant="h5" component="div">
|
<Typography gutterBottom variant="h5" component="div">
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ export default function ProductInfo({ item }: { item: Item }) {
|
|||||||
setImageDimensions({ width: naturalWidth, height: naturalHeight });
|
setImageDimensions({ width: naturalWidth, height: naturalHeight });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const imageUrl = `http://localhost:8085/image?articleId=${item.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={4}>
|
<Grid container spacing={4}>
|
||||||
{/* Left Column - Image */}
|
{/* Left Column - Image */}
|
||||||
@@ -60,9 +62,12 @@ export default function ProductInfo({ item }: { item: Item }) {
|
|||||||
<Card elevation={2} sx={{ width: '100%', maxWidth: 400 }}>
|
<Card elevation={2} sx={{ width: '100%', maxWidth: 400 }}>
|
||||||
<Box
|
<Box
|
||||||
component="img"
|
component="img"
|
||||||
src="/src/assets/HTW.jpg"
|
src={imageUrl}
|
||||||
alt={item.name}
|
alt={item.name}
|
||||||
onLoad={handleImageLoad} // Event-Handler zum Ermitteln der Bildgröße
|
onLoad={handleImageLoad} // Event-Handler zum Ermitteln der Bildgröße
|
||||||
|
onError={(event) => {
|
||||||
|
event.currentTarget.src = "/src/assets/default.jpg"; // Standardbild setzen
|
||||||
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
maxWidth: imageDimensions.width > imageDimensions.height ? "100%" : "auto",
|
maxWidth: imageDimensions.width > imageDimensions.height ? "100%" : "auto",
|
||||||
maxHeight: imageDimensions.height >= imageDimensions.width ? 400 : "auto",
|
maxHeight: imageDimensions.height >= imageDimensions.width ? 400 : "auto",
|
||||||
|
|||||||
Reference in New Issue
Block a user