Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Commit

Permalink
feat: add image transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan-maulana-tkp committed Aug 3, 2020
1 parent 6e1ccad commit 3b150ea
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/routes/Home/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ const { API_URL } = process.env;
function Home() {
const { data, loading } = useData(`${API_URL}/products`, {}, { method: 'GET' }, { ssr: true });

const getResizedImage = (imageUrl) => {
if (imageUrl) {
return `https://res.cloudinary.com/irfan-maulana-tkpd/image/fetch/c_fill,g_auto:face,h_200,fl_force_strip.progressive/f_webp/${encodeURIComponent(imageUrl)}`;
}
return '';
};

return (
<div className="App" data-testid="home-container">
<Header />
Expand All @@ -61,7 +68,7 @@ function Home() {
<div className="products" style={productWrapper}>
{data.data.map(item => (
<Link className="product" style={productCard} key={item.id} to={`/${item.id}`}>
<img className="product__img" style={productImg} src={item.image} alt={item.name}></img>
<img className="product__img" style={productImg} src={getResizedImage(item.image)} alt={item.name}></img>
<div style={productInfo}>
<div style={productName}>{item.name}</div>
<div style={productPrice}>{item.price}</div>
Expand Down

0 comments on commit 3b150ea

Please sign in to comment.