Skip to content
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

fix: add spinner to prevent previous capture appearance #827

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions src/components/CaptureDetailDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Drawer,
Box,
Link,
CircularProgress,
} from '@material-ui/core';
import Close from '@material-ui/icons/Close';
import OptimizedImage from './OptimizedImage';
Expand Down Expand Up @@ -82,6 +83,9 @@ const useStyles = makeStyles((theme) => ({
itemValue: {
lineHeight: 1.7,
},
spinner: {
position: 'fixed',
},
}));

function CaptureDetailDialog(props) {
Expand All @@ -91,6 +95,7 @@ function CaptureDetailDialog(props) {
const [snackbarLabel, setSnackbarLabel] = useState('');
const [renderCapture, setRenderCapture] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [isImageLoading, setIsImageLoading] = useState(true);
const classes = useStyles();

useEffect(() => {
Expand Down Expand Up @@ -135,14 +140,15 @@ function CaptureDetailDialog(props) {
updated_at: current.updated_at || current.timeUpdated,
});
}
if(isLoading) {
if (isLoading) {
setIsLoading(false);
}
setIsImageLoading(true);
}, [cdContext.capture]);

useEffect(() => {
setIsLoading(true);
},[open])
}, [open]);

function handleClose() {
setSnackbarOpen(false);
Expand Down Expand Up @@ -229,7 +235,7 @@ function CaptureDetailDialog(props) {
].map((item) => (
<Grid item key={item.label}>
<Typography variant="subtitle1">{item.label}</Typography>
<Typography variant="body1" className={classes.itemValue}>
<Typography variant="body1" className={classes.itemValue}>
{item.link ? (
// a link is either a GrowerID (item.image == false) or OriginalImage (item.image == true)
item.image ? (
Expand All @@ -243,8 +249,12 @@ function CaptureDetailDialog(props) {
) : (
<LinkToWebmap value={item.value} type="user" />
)
) : item.value ? (
item.value
) : isLoading ? (
<Skeleton variant="text" />
) : (
item.value ? (item.value) : isLoading ? <Skeleton variant="text"/> : '---'
'---'
)}
{item.value && item.copy && (
<CopyButton
Expand All @@ -259,7 +269,11 @@ function CaptureDetailDialog(props) {
<Grid>
<Typography variant="subtitle1">Country</Typography>
<Typography variant="body1" className={classes.itemValue}>
{isLoading ? <Skeleton variant="text"/> : capture?.lat && capture?.lon && countryInfo}
{isLoading ? (
<Skeleton variant="text" />
) : (
capture?.lat && capture?.lon && countryInfo
)}
</Typography>
</Grid>
</Grid>
Expand Down Expand Up @@ -349,13 +363,26 @@ function CaptureDetailDialog(props) {
}}
maxWidth="md"
>
<OptimizedImage
src={renderCapture?.image_url}
width={window.innerHeight * 0.9}
style={{ maxWidth: '100%' }}
objectFit="contain"
fixed
/>
{isLoading ? (
<CircularProgress className={classes.spinner} />
) : (
<>
{isImageLoading && (
<CircularProgress className={classes.spinner} />
)}

<OptimizedImage
src={renderCapture?.image_url}
width={window.innerHeight * 0.9}
style={{ maxWidth: '100%' }}
objectFit="contain"
fixed
onImageReady={() => {
setIsImageLoading(false);
}}
/>
</>
)}
</Dialog>
<Drawer
anchor="right"
Expand Down
4 changes: 4 additions & 0 deletions src/components/OptimizedImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function OptimizedImage(props) {
alertPosition,
alertTextSize,
alertTitleSize,
onImageReady,
objectFit = 'cover',
...rest
} = props;
Expand Down Expand Up @@ -72,6 +73,9 @@ export default function OptimizedImage(props) {
srcSet={srcSet}
sizes={sizes}
loading="lazy"
onLoad={() => {
onImageReady && onImageReady();
}}
style={{
position: 'absolute',
left: 0,
Expand Down