diff --git a/picture-gallery-client/src/ImageGallery/Image.tsx b/picture-gallery-client/src/ImageGallery/Image.tsx index ff8131f..194dbc5 100644 --- a/picture-gallery-client/src/ImageGallery/Image.tsx +++ b/picture-gallery-client/src/ImageGallery/Image.tsx @@ -2,18 +2,23 @@ import { PhotoProps } from "react-photo-album"; import React from "react"; import { Backdrop } from "@mui/material"; import { ImageWithThumbnail } from "./models"; +import { Spinner } from "./Spinner"; export const Image = ({ imageProps: { alt, style, src: _useSrcAndThumbnailFromPhoto, ...rest }, photo, }: PhotoProps): JSX.Element => { const [open, setOpen] = React.useState(false); + const [loaded, setLoaded] = React.useState(false); const handleClose = () => { setOpen(false); }; const handleToggle = () => { setOpen(!open); }; + const handleImageLoaded = () => { + setLoaded(true); + }; return ( <> @@ -26,13 +31,25 @@ export const Image = ({ src={photo.thumbnail} onClick={handleToggle} /> - theme.zIndex.drawer + 1 }} - open={open} - onClick={handleClose} - > - {alt} - + {open && ( + theme.zIndex.drawer + 1 }} + open={open} + onClick={handleClose} + > + {!loaded && } + {alt} + + )} ); }; diff --git a/picture-gallery-client/src/ImageGallery/Spinner.tsx b/picture-gallery-client/src/ImageGallery/Spinner.tsx new file mode 100644 index 0000000..5d226ab --- /dev/null +++ b/picture-gallery-client/src/ImageGallery/Spinner.tsx @@ -0,0 +1,12 @@ +import env from "../env"; +import { CircularProgress } from "@mui/material"; +import React from "react"; + +export const Spinner = (): JSX.Element => { + return ( + + ); +}; diff --git a/picture-gallery-client/src/ImageGalleryLayout.tsx b/picture-gallery-client/src/ImageGalleryLayout.tsx index b25ee72..ac96d09 100644 --- a/picture-gallery-client/src/ImageGalleryLayout.tsx +++ b/picture-gallery-client/src/ImageGalleryLayout.tsx @@ -2,14 +2,13 @@ import React, { useEffect, useState } from "react"; import Box from "@mui/material/Box"; import CssBaseline from "@mui/material/CssBaseline"; import { useLocation, useNavigate } from "react-router-dom"; -import { CircularProgress } from "@mui/material"; import { Folders, ImageWithThumbnail } from "./ImageGallery/models"; import ImageGalleryAppBar from "./ImageGallery/ImageGalleryAppBar"; import DrawerHeader from "./MuiLayout/DrawerHeader"; import ImageGalleryDrawer from "./ImageGallery/ImageGalleryDrawer"; import ImageGallery from "./ImageGallery/ImageGallery"; import Main from "./MuiLayout/Main"; -import env from "./env"; +import { Spinner } from "./ImageGallery/Spinner"; const drawerWidth = 240; @@ -87,13 +86,7 @@ function ImageGalleryLayout() { />
- {imagesLoaded ? ( - - ) : ( - - )} + {imagesLoaded ? : }
); diff --git a/picture-gallery-client/src/index.tsx b/picture-gallery-client/src/index.tsx index bc7a182..2335407 100644 --- a/picture-gallery-client/src/index.tsx +++ b/picture-gallery-client/src/index.tsx @@ -12,9 +12,11 @@ const root = ReactDOM.createRoot( document.getElementById("root") as HTMLElement ); root.render( - - - + + + + + ); // If you want to start measuring performance in your app, pass a function