-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: planter selfie rotation #142
Changes from 4 commits
a636045
1863c6b
624f386
d2de60e
6c2305f
ee65107
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react'; | |
import { makeStyles } from '@material-ui/core/styles'; | ||
import { Fab, Grid, CircularProgress, Card, Button } from '@material-ui/core'; | ||
import { ChevronLeft, ChevronRight } from '@material-ui/icons'; | ||
import Rotate90DegreesCcwIcon from '@material-ui/icons/Rotate90DegreesCcw'; | ||
import OptimizedImage from './OptimizedImage'; | ||
|
||
/* This component currently uses fixed size cards and scroll window, | ||
|
@@ -29,7 +30,7 @@ const useStyle = makeStyles((theme) => ({ | |
textAlign: 'center', | ||
}, | ||
imageCard: { | ||
height: '100%', | ||
height: '84%', | ||
margin: theme.spacing(1.5), | ||
width: `${IMAGE_CARD_SIZE - theme.spacing(3)}px`, | ||
cursor: 'pointer', | ||
|
@@ -65,20 +66,38 @@ const useStyle = makeStyles((theme) => ({ | |
textAlign: 'center', | ||
height: '100%', | ||
}, | ||
clickRotate: { | ||
margin: 5, | ||
position: 'absolute', | ||
bottom: 0, | ||
right: 0, | ||
width: 32, | ||
height: 32, | ||
}, | ||
})); | ||
|
||
export default function ImageScroller(props) { | ||
const { | ||
images, | ||
selectedImage, | ||
onSelectImage, | ||
loading = false, | ||
blankMessage = '', | ||
imageRotation, | ||
onSelectChange, | ||
} = props; | ||
|
||
const classes = useStyle(); | ||
const [maxImages, setMaxImages] = useState(MAX_IMAGES_INCREMENT); | ||
const imageScrollerRef = useRef(null); | ||
let objRotation = {}; | ||
if (selectedImage) { | ||
const selectedIndex = images.indexOf(selectedImage); | ||
objRotation[selectedIndex] = imageRotation; | ||
} else { | ||
images.map((_, idx) => { | ||
objRotation[idx] = imageRotation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't really make sense to apply image rotation to all images if none is selected. |
||
}); | ||
} | ||
let [rotations, setRotations] = useState(objRotation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is introducing unnecessary complexity. |
||
|
||
function loadMoreImages() { | ||
setMaxImages(maxImages + MAX_IMAGES_INCREMENT); | ||
|
@@ -103,6 +122,16 @@ export default function ImageScroller(props) { | |
}); | ||
} | ||
|
||
function handleRotationChange(idx) { | ||
let newRotation = | ||
rotations[idx] >= 0 ? rotations[idx] + 90 : imageRotation + 90; | ||
if (newRotation === 360) { | ||
newRotation = 0; | ||
} | ||
setRotations({ ...rotations, [idx]: newRotation }); | ||
onSelectChange('imageRotation', newRotation); | ||
} | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<Grid | ||
|
@@ -118,7 +147,6 @@ export default function ImageScroller(props) { | |
images.slice(0, maxImages).map((img, idx) => ( | ||
<Card | ||
key={`${idx}_${img}`} | ||
onClick={() => onSelectImage(img)} | ||
className={`image-card ${classes.imageCard} ${ | ||
img === selectedImage && classes.selectedImageCard | ||
}`} | ||
|
@@ -129,7 +157,22 @@ export default function ImageScroller(props) { | |
height={192} | ||
className={classes.image} | ||
fixed | ||
rotation={rotations[idx] ? rotations[idx] : imageRotation} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest reverting back to the single value, but only applying it if this is the selected image. |
||
onClick={() => onSelectChange('imageUrl', img)} | ||
/> | ||
{img === selectedImage ? ( | ||
<Fab | ||
id="click-rotate" | ||
className={classes.clickRotate} | ||
onClick={() => handleRotationChange(idx)} | ||
> | ||
<Rotate90DegreesCcwIcon | ||
style={{ transform: `rotateY(180deg)` }} | ||
/> | ||
</Fab> | ||
) : ( | ||
'' | ||
)} | ||
</Card> | ||
)) | ||
) : ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,6 @@ import OptimizedImage from './OptimizedImage'; | |
import LinkToWebmap from './common/LinkToWebmap'; | ||
|
||
const useStyle = makeStyles((theme) => ({ | ||
root: { | ||
width: 441, | ||
}, | ||
box: { | ||
padding: theme.spacing(4), | ||
}, | ||
|
@@ -108,7 +105,14 @@ const PlanterDetail = (props) => { | |
return ( | ||
<React.Fragment> | ||
<Drawer anchor="right" open={props.open} onClose={props.onClose}> | ||
<Grid className={classes.root}> | ||
<Grid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make the container and image square to avoid this awkwardness and inconsistency between rotated and unrotated images. The planter card can also be updated to use a square image. |
||
style={{ | ||
width: | ||
planter.imageRotation === 0 || planter.imageRotation === 180 | ||
? 441 | ||
: 378, | ||
}} | ||
> | ||
<Grid container direction="column"> | ||
<Grid item> | ||
<Grid container justify="space-between" alignItems="center"> | ||
|
@@ -134,6 +138,7 @@ const PlanterDetail = (props) => { | |
height={378} | ||
className={classes.cardMedia} | ||
fixed | ||
rotation={planter.imageRotation} | ||
/> | ||
)} | ||
{!planter.imageUrl && ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it simple and make these images square.