diff --git a/ui/v2.5/src/components/Galleries/GalleryGridCard.tsx b/ui/v2.5/src/components/Galleries/GalleryGridCard.tsx new file mode 100644 index 000000000..d033bd233 --- /dev/null +++ b/ui/v2.5/src/components/Galleries/GalleryGridCard.tsx @@ -0,0 +1,38 @@ +import React, { useRef } from "react"; +import * as GQL from "src/core/generated-graphql"; +import { GalleryCard } from "./GalleryCard"; +import { useContainerDimensions } from "../Shared/GridCard/GridCard"; + +interface IGalleryCardGrid { + galleries: GQL.SlimGalleryDataFragment[]; + selectedIds: Set; + zoomIndex: number; + onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void; +} + +export const GalleryCardGrid: React.FC = ({ + galleries, + selectedIds, + zoomIndex, + onSelectChange, +}) => { + const componentRef = useRef(null); + const { width } = useContainerDimensions(componentRef); + return ( +
+ {galleries.map((gallery) => ( + 0} + selected={selectedIds.has(gallery.id)} + onSelectedChanged={(selected: boolean, shiftKey: boolean) => + onSelectChange(gallery.id, selected, shiftKey) + } + /> + ))} +
+ ); +}; diff --git a/ui/v2.5/src/components/Galleries/GalleryList.tsx b/ui/v2.5/src/components/Galleries/GalleryList.tsx index 6bc842082..3ef5acf1f 100644 --- a/ui/v2.5/src/components/Galleries/GalleryList.tsx +++ b/ui/v2.5/src/components/Galleries/GalleryList.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from "react"; +import React, { useState } from "react"; import { useIntl } from "react-intl"; import cloneDeep from "lodash-es/cloneDeep"; import { useHistory } from "react-router-dom"; @@ -12,13 +12,12 @@ import { import { ListFilterModel } from "src/models/list-filter/filter"; import { DisplayMode } from "src/models/list-filter/types"; import { queryFindGalleries, useFindGalleries } from "src/core/StashService"; -import { GalleryCard } from "./GalleryCard"; import GalleryWallCard from "./GalleryWallCard"; import { EditGalleriesDialog } from "./EditGalleriesDialog"; import { DeleteGalleriesDialog } from "./DeleteGalleriesDialog"; import { ExportDialog } from "../Shared/ExportDialog"; import { GalleryListTable } from "./GalleryListTable"; -import { useContainerDimensions } from "../Shared/GridCard/GridCard"; +import { GalleryCardGrid } from "./GalleryGridCard"; const GalleryItemList = makeItemList({ filterMode: GQL.FilterMode.Galleries, @@ -107,9 +106,6 @@ export const GalleryList: React.FC = ({ setIsExportDialogOpen(true); } - const componentRef = useRef(null); - const { width } = useContainerDimensions(componentRef); - function renderContent( result: GQL.FindGalleriesQueryResult, filter: ListFilterModel, @@ -137,21 +133,12 @@ export const GalleryList: React.FC = ({ if (filter.displayMode === DisplayMode.Grid) { return ( -
- {result.data.findGalleries.galleries.map((gallery) => ( - 0} - selected={selectedIds.has(gallery.id)} - onSelectedChanged={(selected: boolean, shiftKey: boolean) => - onSelectChange(gallery.id, selected, shiftKey) - } - /> - ))} -
+ ); } if (filter.displayMode === DisplayMode.List) { diff --git a/ui/v2.5/src/components/Images/ImageGridCard.tsx b/ui/v2.5/src/components/Images/ImageGridCard.tsx new file mode 100644 index 000000000..94b20f51d --- /dev/null +++ b/ui/v2.5/src/components/Images/ImageGridCard.tsx @@ -0,0 +1,43 @@ +import React, { useRef } from "react"; +import * as GQL from "src/core/generated-graphql"; +import { ImageCard } from "./ImageCard"; +import { useContainerDimensions } from "../Shared/GridCard/GridCard"; + +interface IImageCardGrid { + images: GQL.SlimImageDataFragment[]; + selectedIds: Set; + zoomIndex: number; + onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void; + onPreview: (index: number, ev: React.MouseEvent) => void; +} + +export const ImageGridCard: React.FC = ({ + images, + selectedIds, + zoomIndex, + onSelectChange, + onPreview, +}) => { + const componentRef = useRef(null); + const { width } = useContainerDimensions(componentRef); + return ( +
+ {images.map((image, index) => ( + 0} + selected={selectedIds.has(image.id)} + onSelectedChanged={(selected: boolean, shiftKey: boolean) => + onSelectChange(image.id, selected, shiftKey) + } + onPreview={ + selectedIds.size < 1 ? (ev) => onPreview(index, ev) : undefined + } + /> + ))} +
+ ); +}; diff --git a/ui/v2.5/src/components/Images/ImageList.tsx b/ui/v2.5/src/components/Images/ImageList.tsx index df244fc3e..c0339a44c 100644 --- a/ui/v2.5/src/components/Images/ImageList.tsx +++ b/ui/v2.5/src/components/Images/ImageList.tsx @@ -4,7 +4,6 @@ import React, { useMemo, MouseEvent, useContext, - useRef, } from "react"; import { FormattedNumber, useIntl } from "react-intl"; import cloneDeep from "lodash-es/cloneDeep"; @@ -22,7 +21,6 @@ import { useLightbox } from "src/hooks/Lightbox/hooks"; import { ListFilterModel } from "src/models/list-filter/filter"; import { DisplayMode } from "src/models/list-filter/types"; -import { ImageCard } from "./ImageCard"; import { ImageWallItem } from "./ImageWallItem"; import { EditImagesDialog } from "./EditImagesDialog"; import { DeleteImagesDialog } from "./DeleteImagesDialog"; @@ -32,7 +30,7 @@ import { ExportDialog } from "../Shared/ExportDialog"; import { objectTitle } from "src/core/files"; import TextUtils from "src/utils/text"; import { ConfigurationContext } from "src/hooks/Config"; -import { useContainerDimensions } from "../Shared/GridCard/GridCard"; +import { ImageGridCard } from "./ImageGridCard"; interface IImageWallProps { images: GQL.SlimImageDataFragment[]; @@ -197,39 +195,15 @@ const ImageListImages: React.FC = ({ ev.preventDefault(); } - const componentRef = useRef(null); - const { width } = useContainerDimensions(componentRef); - - function renderImageCard( - index: number, - image: GQL.SlimImageDataFragment, - zoomIndex: number - ) { - return ( - 0} - selected={selectedIds.has(image.id)} - onSelectedChanged={(selected: boolean, shiftKey: boolean) => - onSelectChange(image.id, selected, shiftKey) - } - onPreview={ - selectedIds.size < 1 ? (ev) => onPreview(index, ev) : undefined - } - /> - ); - } - if (filter.displayMode === DisplayMode.Grid) { return ( -
- {images.map((image, index) => - renderImageCard(index, image, filter.zoomIndex) - )} -
+ ); } if (filter.displayMode === DisplayMode.Wall) {