Show original image in big picture mode
This commit is contained in:
parent
1d038f84a2
commit
ff0d3f676e
|
|
@ -1,10 +1,12 @@
|
||||||
import { PhotoProps, RenderPhoto } from "react-photo-album";
|
import { PhotoProps } from "react-photo-album";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Backdrop } from "@mui/material";
|
import { Backdrop } from "@mui/material";
|
||||||
|
import { ImageWithThumbnail } from "./models";
|
||||||
|
|
||||||
export const Image: RenderPhoto = ({
|
export const Image = <T extends ImageWithThumbnail>({
|
||||||
imageProps: { alt, style, ...rest },
|
imageProps: { alt, style, src: _useSrcAndThumbnailFromPhoto, ...rest },
|
||||||
}: PhotoProps): JSX.Element => {
|
photo,
|
||||||
|
}: PhotoProps<T>): JSX.Element => {
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
|
@ -21,6 +23,7 @@ export const Image: RenderPhoto = ({
|
||||||
...style,
|
...style,
|
||||||
}}
|
}}
|
||||||
{...rest}
|
{...rest}
|
||||||
|
src={photo.thumbnail}
|
||||||
onClick={handleToggle}
|
onClick={handleToggle}
|
||||||
/>
|
/>
|
||||||
<Backdrop
|
<Backdrop
|
||||||
|
|
@ -28,7 +31,7 @@ export const Image: RenderPhoto = ({
|
||||||
open={open}
|
open={open}
|
||||||
onClick={handleClose}
|
onClick={handleClose}
|
||||||
>
|
>
|
||||||
<img alt={alt} {...rest} />
|
<img alt={alt} {...rest} src={photo.src} />
|
||||||
</Backdrop>
|
</Backdrop>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import PhotoAlbum, { Photo } from "react-photo-album";
|
import PhotoAlbum from "react-photo-album";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Image } from "./Image";
|
import { Image } from "./Image";
|
||||||
|
import { ImageWithThumbnail } from "./models";
|
||||||
|
|
||||||
function ImageGallery({ images }: { images: Photo[] }) {
|
function ImageGallery({ images }: { images: ImageWithThumbnail[] }) {
|
||||||
// For all kind of settings see:
|
// For all kind of settings see:
|
||||||
// https://react-photo-album.com/examples/playground
|
// https://react-photo-album.com/examples/playground
|
||||||
// https://codesandbox.io/s/github/igordanchenko/react-photo-album/tree/main/examples/playground
|
// https://codesandbox.io/s/github/igordanchenko/react-photo-album/tree/main/examples/playground
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
|
import { Photo } from "react-photo-album";
|
||||||
|
|
||||||
export interface Folders {
|
export interface Folders {
|
||||||
name: string;
|
name: string;
|
||||||
fullPath: string;
|
fullPath: string;
|
||||||
numberOfFiles: number;
|
numberOfFiles: number;
|
||||||
children: Folders[];
|
children: Folders[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ImageWithThumbnail extends Photo {
|
||||||
|
thumbnail: string;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Photo } from "react-photo-album";
|
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import CssBaseline from "@mui/material/CssBaseline";
|
import CssBaseline from "@mui/material/CssBaseline";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
import { Folders } from "./ImageGallery/models";
|
import { Folders, ImageWithThumbnail } from "./ImageGallery/models";
|
||||||
import ImageGalleryAppBar from "./ImageGallery/ImageGalleryAppBar";
|
import ImageGalleryAppBar from "./ImageGallery/ImageGalleryAppBar";
|
||||||
import DrawerHeader from "./MuiLayout/DrawerHeader";
|
import DrawerHeader from "./MuiLayout/DrawerHeader";
|
||||||
import ImageGalleryDrawer from "./ImageGallery/ImageGalleryDrawer";
|
import ImageGalleryDrawer from "./ImageGallery/ImageGalleryDrawer";
|
||||||
|
|
@ -18,7 +17,7 @@ function ImageGalleryLayout() {
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [imagesLoaded, setImagesLoaded] = useState(false);
|
const [imagesLoaded, setImagesLoaded] = useState(false);
|
||||||
const [images, setImages] = useState<Photo[]>([]);
|
const [images, setImages] = useState<ImageWithThumbnail[]>([]);
|
||||||
const [folders, setFolders] = useState<Folders>({
|
const [folders, setFolders] = useState<Folders>({
|
||||||
name: "Home",
|
name: "Home",
|
||||||
fullPath: "/",
|
fullPath: "/",
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,17 @@ const readThumbnails = (requestedPath: string): string[] => {
|
||||||
: [];
|
: [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSrc = (
|
const getSrc = (requestedPath: string, f: Dirent): string =>
|
||||||
|
path.posix.join("/staticImages", requestedPath, f.name);
|
||||||
|
|
||||||
|
const getThumbnail = (
|
||||||
thumbnailExists: boolean,
|
thumbnailExists: boolean,
|
||||||
requestedPath: string,
|
requestedPath: string,
|
||||||
f: Dirent
|
f: Dirent
|
||||||
): string =>
|
): string =>
|
||||||
thumbnailExists
|
thumbnailExists
|
||||||
? path.posix.join("/staticImages", thumbnailPath, requestedPath, f.name)
|
? path.posix.join("/staticImages", thumbnailPath, requestedPath, f.name)
|
||||||
: path.posix.join("/staticImages", requestedPath, f.name);
|
: getSrc(requestedPath, f);
|
||||||
|
|
||||||
const toImage = (
|
const toImage = (
|
||||||
metadata: sharp.Metadata,
|
metadata: sharp.Metadata,
|
||||||
|
|
@ -45,7 +48,8 @@ const toImage = (
|
||||||
): Image => {
|
): Image => {
|
||||||
const widthAndHeightSwap = metadata.orientation > 4; // see https://exiftool.org/TagNames/EXIF.html
|
const widthAndHeightSwap = metadata.orientation > 4; // see https://exiftool.org/TagNames/EXIF.html
|
||||||
return a<Image>({
|
return a<Image>({
|
||||||
src: getSrc(thumbnailExists, requestedPath, f),
|
src: getSrc(requestedPath, f),
|
||||||
|
thumbnail: getThumbnail(thumbnailExists, requestedPath, f),
|
||||||
width: widthAndHeightSwap ? metadata.height : metadata.width,
|
width: widthAndHeightSwap ? metadata.height : metadata.width,
|
||||||
height: widthAndHeightSwap ? metadata.width : metadata.height,
|
height: widthAndHeightSwap ? metadata.width : metadata.height,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
export interface Image {
|
export interface Image {
|
||||||
src: string;
|
src: string;
|
||||||
|
thumbnail: string;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue