mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
* Add hook for grid card width calculation * Move card width calculation into grid instead of card Now calculates once instead of per card * Debounce resize observer
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import React from "react";
|
|
import * as GQL from "src/core/generated-graphql";
|
|
import { GalleryCard } from "./GalleryCard";
|
|
import {
|
|
useCardWidth,
|
|
useContainerDimensions,
|
|
} from "../Shared/GridCard/GridCard";
|
|
|
|
interface IGalleryCardGrid {
|
|
galleries: GQL.SlimGalleryDataFragment[];
|
|
selectedIds: Set<string>;
|
|
zoomIndex: number;
|
|
onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void;
|
|
}
|
|
|
|
const zoomWidths = [280, 340, 480, 640];
|
|
|
|
export const GalleryCardGrid: React.FC<IGalleryCardGrid> = ({
|
|
galleries,
|
|
selectedIds,
|
|
zoomIndex,
|
|
onSelectChange,
|
|
}) => {
|
|
const [componentRef, { width: containerWidth }] = useContainerDimensions();
|
|
const cardWidth = useCardWidth(containerWidth, zoomIndex, zoomWidths);
|
|
|
|
return (
|
|
<div className="row justify-content-center" ref={componentRef}>
|
|
{galleries.map((gallery) => (
|
|
<GalleryCard
|
|
key={gallery.id}
|
|
cardWidth={cardWidth}
|
|
gallery={gallery}
|
|
zoomIndex={zoomIndex}
|
|
selecting={selectedIds.size > 0}
|
|
selected={selectedIds.has(gallery.id)}
|
|
onSelectedChanged={(selected: boolean, shiftKey: boolean) =>
|
|
onSelectChange(gallery.id, selected, shiftKey)
|
|
}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|