Fit cards properly within their containers (#4514)

* created missing cards grids
This commit is contained in:
CJ
2024-02-05 20:06:47 -06:00
committed by GitHub
parent 330581283a
commit a8df95c3a4
25 changed files with 460 additions and 124 deletions

View File

@@ -1,4 +1,4 @@
import React, { MouseEvent, useMemo } from "react";
import React, { MouseEvent, useEffect, useMemo, useState } from "react";
import { Button, ButtonGroup } from "react-bootstrap";
import cx from "classnames";
import * as GQL from "src/core/generated-graphql";
@@ -7,7 +7,7 @@ import { GalleryLink, TagLink } from "src/components/Shared/TagLink";
import { HoverPopover } from "src/components/Shared/HoverPopover";
import { SweatDrops } from "src/components/Shared/SweatDrops";
import { PerformerPopoverButton } from "src/components/Shared/PerformerPopoverButton";
import { GridCard } from "src/components/Shared/GridCard";
import { GridCard, calculateCardWidth } from "src/components/Shared/GridCard";
import { RatingBanner } from "src/components/Shared/RatingBanner";
import {
faBox,
@@ -17,9 +17,11 @@ import {
} from "@fortawesome/free-solid-svg-icons";
import { objectTitle } from "src/core/files";
import { TruncatedText } from "../Shared/TruncatedText";
import ScreenUtils from "src/utils/screen";
interface IImageCardProps {
image: GQL.SlimImageDataFragment;
containerWidth?: number;
selecting?: boolean;
selected?: boolean | undefined;
zoomIndex: number;
@@ -30,6 +32,38 @@ interface IImageCardProps {
export const ImageCard: React.FC<IImageCardProps> = (
props: IImageCardProps
) => {
const [cardWidth, setCardWidth] = useState<number>();
useEffect(() => {
if (
!props.containerWidth ||
props.zoomIndex === undefined ||
ScreenUtils.isMobile()
)
return;
let zoomValue = props.zoomIndex;
let preferredCardWidth: number;
switch (zoomValue) {
case 0:
preferredCardWidth = 240;
break;
case 1:
preferredCardWidth = 340;
break;
case 2:
preferredCardWidth = 480;
break;
case 3:
preferredCardWidth = 640;
}
let fittedCardWidth = calculateCardWidth(
props.containerWidth,
preferredCardWidth!
);
setCardWidth(fittedCardWidth);
}, [props, props.containerWidth, props.zoomIndex]);
const file = useMemo(
() =>
props.image.visual_files.length > 0
@@ -153,6 +187,7 @@ export const ImageCard: React.FC<IImageCardProps> = (
<GridCard
className={`image-card zoom-${props.zoomIndex}`}
url={`/images/${props.image.id}`}
width={cardWidth}
title={objectTitle(props.image)}
linkClassName="image-card-link"
image={