diff --git a/ui/v2.5/src/components/Galleries/GalleryWallCard.tsx b/ui/v2.5/src/components/Galleries/GalleryWallCard.tsx index f38103d53..c794ddc14 100644 --- a/ui/v2.5/src/components/Galleries/GalleryWallCard.tsx +++ b/ui/v2.5/src/components/Galleries/GalleryWallCard.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { useIntl } from "react-intl"; import { Link } from "react-router-dom"; import * as GQL from "src/core/generated-graphql"; @@ -7,32 +7,50 @@ import TextUtils from "src/utils/text"; import { useGalleryLightbox } from "src/hooks/Lightbox/hooks"; import { galleryTitle } from "src/core/galleries"; import { RatingSystem } from "../Shared/Rating/RatingSystem"; +import { GalleryPreviewScrubber } from "./GalleryPreviewScrubber"; +import cx from "classnames"; const CLASSNAME = "GalleryWallCard"; const CLASSNAME_FOOTER = `${CLASSNAME}-footer`; const CLASSNAME_IMG = `${CLASSNAME}-img`; const CLASSNAME_TITLE = `${CLASSNAME}-title`; +const CLASSNAME_IMG_CONTAIN = `${CLASSNAME}-img-contain`; interface IProps { gallery: GQL.SlimGalleryDataFragment; } +type Orientation = "landscape" | "portrait"; + +function getOrientation(width: number, height: number): Orientation { + return width > height ? "landscape" : "portrait"; +} + const GalleryWallCard: React.FC = ({ gallery }) => { const intl = useIntl(); - const [orientation, setOrientation] = React.useState< - "landscape" | "portrait" - >("landscape"); + const [coverOrientation, setCoverOrientation] = + React.useState("landscape"); + const [imageOrientation, setImageOrientation] = + React.useState("landscape"); const showLightbox = useGalleryLightbox(gallery.id, gallery.chapters); const cover = gallery?.paths.cover; - function onImageLoad(e: React.SyntheticEvent) { + function onCoverLoad(e: React.SyntheticEvent) { const target = e.target as HTMLImageElement; - setOrientation( - target.naturalWidth > target.naturalHeight ? "landscape" : "portrait" + setCoverOrientation( + getOrientation(target.naturalWidth, target.naturalHeight) ); } + function onNonCoverLoad(e: React.SyntheticEvent) { + const target = e.target as HTMLImageElement; + setImageOrientation( + getOrientation(target.naturalWidth, target.naturalHeight) + ); + } + + const [imgSrc, setImgSrc] = useState(cover ?? undefined); const title = galleryTitle(gallery); const performerNames = gallery.performers.map((p) => p.name); const performers = @@ -48,10 +66,13 @@ const GalleryWallCard: React.FC = ({ gallery }) => { showLightbox(0); } + const imgClassname = + imageOrientation !== coverOrientation ? CLASSNAME_IMG_CONTAIN : ""; + return ( <>
= ({ gallery }) => { -
- e.stopPropagation()} - > - {title && ( - - )} - -
- {gallery.date && TextUtils.formatDate(intl, gallery.date)} -
- -
+
+
+ e.stopPropagation()} + > + {title && ( + + )} + +
+ {gallery.date && TextUtils.formatDate(intl, gallery.date)} +
+ +
+ { + showLightbox(i); + }} + onPathChanged={setImgSrc} + /> +
); diff --git a/ui/v2.5/src/components/Galleries/styles.scss b/ui/v2.5/src/components/Galleries/styles.scss index d23149552..12439a94d 100644 --- a/ui/v2.5/src/components/Galleries/styles.scss +++ b/ui/v2.5/src/components/Galleries/styles.scss @@ -237,6 +237,18 @@ $galleryTabWidth: 450px; width: 96vw; } + .lineargradient { + background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.3)); + bottom: 100px; + height: 100px; + position: relative; + } + + .preview-scrubber { + top: 0; + z-index: 1; + } + @mixin galleryWidth($width) { height: math.div($width, 3) * 2; @@ -264,6 +276,11 @@ $galleryTabWidth: 450px; object-fit: cover; object-position: center 20%; width: 100%; + + &.GalleryWallCard-img-contain { + object-fit: contain; + object-position: initial; + } } &-title { @@ -271,13 +288,13 @@ $galleryTabWidth: 450px; } &-footer { - background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.3)); - bottom: 0; + bottom: 20px; padding: 1rem; position: absolute; text-shadow: 1px 1px 3px black; transition: 0s opacity; width: 100%; + z-index: 2; @media (min-width: 768px) { opacity: 0; @@ -310,6 +327,7 @@ $galleryTabWidth: 450px; right: 1rem; text-shadow: 1px 1px 3px black; top: 1rem; + z-index: 2; } .rating-stars { diff --git a/ui/v2.5/src/components/Shared/HoverScrubber.tsx b/ui/v2.5/src/components/Shared/HoverScrubber.tsx index d42f06ae7..e9f3f8209 100644 --- a/ui/v2.5/src/components/Shared/HoverScrubber.tsx +++ b/ui/v2.5/src/components/Shared/HoverScrubber.tsx @@ -76,6 +76,7 @@ export const HoverScrubber: React.FC = ({ return; e.preventDefault(); + e.stopPropagation(); onClick(); }