Skip to content

Commit

Permalink
feat: use OpitimizedImage for CaptureImage
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Feb 7, 2022
1 parent 08d6de0 commit ace635f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/components/CaptureMatching/CaptureImage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';

import CaptureHeader from './CaptureHeader';
import Grower from './Grower';

import OptimizedImage from '../OptimizedImage';
import { Tooltip, Typography, Box, Button, Paper } from '@material-ui/core';
import AccessTimeIcon from '@material-ui/icons/AccessTime';
import LocationOnOutlinedIcon from '@material-ui/icons/LocationOnOutlined';
Expand Down Expand Up @@ -103,9 +103,22 @@ function CaptureImage(props) {
imgCount,
handleSkip,
} = props;

const [screenWidth, setScreenWidth] = useState(window.innerWidth);
const [screenHeight, setScreenHeight] = useState(window.innerHeight);
const classes = useStyles();

const resizeWindow = useCallback(() => {
setScreenWidth(window.innerWidth);
setScreenHeight(window.innerHeight);
}, []);

useEffect(() => {
window.addEventListener('resize', resizeWindow);
return () => {
window.removeEventListener('resize', resizeWindow);
};
}, [resizeWindow]);

return (
<Box className={classes.box1}>
<CaptureHeader
Expand Down Expand Up @@ -168,11 +181,13 @@ function CaptureImage(props) {
</Box>

<Box className={classes.imgBox}>
<img
key={capture.id}
className={classes.imgContainer}
<OptimizedImage
id={capture.id}
src={capture.image_url}
alt={`Capture ${capture.id}`}
width={screenWidth * 0.5}
height={screenHeight * 0.6}
style={{ maxWidth: '100%', maxHeight: '100%' }}
/>
</Box>
</Paper>
Expand Down

0 comments on commit ace635f

Please sign in to comment.