diff --git a/frontend/src/Photos/Overview.scss b/frontend/src/Photos/Overview.scss index ea08413..33057fc 100644 --- a/frontend/src/Photos/Overview.scss +++ b/frontend/src/Photos/Overview.scss @@ -26,6 +26,7 @@ object-fit: contain; max-height: 100%; max-width: 100%; + min-height: 100%; width: auto; height: auto; box-shadow: $pt-elevation-shadow-4; diff --git a/frontend/src/Photos/Photo.scss b/frontend/src/Photos/Photo.scss index 6fd3f1a..1ecc954 100644 --- a/frontend/src/Photos/Photo.scss +++ b/frontend/src/Photos/Photo.scss @@ -1,7 +1,5 @@ @import "~@blueprintjs/core/lib/scss/variables"; - - .bp3-dark { #photoView {} } \ No newline at end of file diff --git a/frontend/src/Photos/Photo.tsx b/frontend/src/Photos/Photo.tsx index aa94262..cfd37ed 100644 --- a/frontend/src/Photos/Photo.tsx +++ b/frontend/src/Photos/Photo.tsx @@ -4,10 +4,15 @@ import { connect } from "react-redux"; import { Dispatch } from "redux"; import { IPhotoReqJSON } from "~../../src/entity/Photo"; import { LoadingStub } from "~LoadingStub"; -import { getPhotoImgPath, getPhotoThumbPath } from "~redux/api/photos"; +import { + fetchPhoto, + getPhotoImgPath, + getPhotoThumbPath, +} from "~redux/api/photos"; import { photoLoadStart } from "~redux/photos/actions"; import { IPhotoState } from "~redux/photos/reducer"; import { IAppState } from "~redux/reducers"; +import { LargeSize, PreviewSize } from "./helper"; export interface IPhotoComponentProps { id: number; @@ -20,7 +25,36 @@ export interface IPhotoComponentProps { export const PhotoComponent: React.FunctionComponent = ( props, ) => { - const [loaded, setLoaded] = React.useState(false); + const [smallPreview, setSmallPreview] = React.useState(null); + const [largePreview, setLargePreview] = React.useState(null); + const [original, setOriginal] = React.useState(null); + const imgRef = React.useRef(null); + + React.useEffect(() => { + async function fetchSizes() { + if (props.photo && !smallPreview) { + const smallPreviewFetch = await fetch( + getPhotoThumbPath(props.photo, PreviewSize), + ); + setSmallPreview( + URL.createObjectURL(await smallPreviewFetch.blob()), + ); + } + if (props.photo && !largePreview) { + const largePreviewFetch = await fetch( + getPhotoThumbPath(props.photo, LargeSize), + ); + setLargePreview( + URL.createObjectURL(await largePreviewFetch.blob()), + ); + } + if (props.photo && !original) { + const originalFetch = await fetch(getPhotoImgPath(props.photo)); + setOriginal(URL.createObjectURL(await originalFetch.blob())); + } + } + void fetchSizes(); + }); if (!props.photo && !props.photoState?.fetching) { props.fetchPhoto(props.id); @@ -28,7 +62,6 @@ export const PhotoComponent: React.FunctionComponent = ( if (!props.photo) { return ; } - const fileExists = props.photo.uploaded; return ( @@ -36,10 +69,14 @@ export const PhotoComponent: React.FunctionComponent = ( {fileExists ? (
setLoaded(true)} - src={getPhotoThumbPath(props.photo, 2048)} + src={ + original || + largePreview || + smallPreview || + getPhotoThumbPath(props.photo, PreviewSize) + } />
) : ( diff --git a/frontend/src/Photos/PhotoCard.tsx b/frontend/src/Photos/PhotoCard.tsx index 8388519..707ba32 100644 --- a/frontend/src/Photos/PhotoCard.tsx +++ b/frontend/src/Photos/PhotoCard.tsx @@ -16,6 +16,7 @@ import { photoDeleteCancel, photoDeleteStart } from "~redux/photos/actions"; import { connect } from "react-redux"; import { LoadingStub } from "~LoadingStub"; import { RouteComponentProps, withRouter } from "react-router"; +import { LargeSize, PreviewSize } from "./helper"; export interface IPhotoCardComponentProps extends RouteComponentProps { photo: IPhotoReqJSON; @@ -76,12 +77,12 @@ export class PhotoCardComponent extends React.PureComponent< > {fileExists ? ( this.setLoaded(true)} onMouseEnter={() => preloadImage( - getPhotoThumbPath(this.props.photo, 2048), + getPhotoThumbPath(this.props.photo, LargeSize), ) } > diff --git a/frontend/src/Photos/helper.tsx b/frontend/src/Photos/helper.tsx new file mode 100644 index 0000000..cd556a1 --- /dev/null +++ b/frontend/src/Photos/helper.tsx @@ -0,0 +1,2 @@ +export const PreviewSize = 512; +export const LargeSize = 2048;