Fix unset gallery card width on initialization (#4612)

This commit is contained in:
CJ
2024-02-27 23:10:15 +01:00
committed by GitHub
parent 98c428ba4e
commit 768f74a0b3
4 changed files with 97 additions and 55 deletions

View File

@@ -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<string>;
zoomIndex: number;
onSelectChange: (id: string, selected: boolean, shiftKey: boolean) => void;
}
export const GalleryCardGrid: React.FC<IGalleryCardGrid> = ({
galleries,
selectedIds,
zoomIndex,
onSelectChange,
}) => {
const componentRef = useRef<HTMLDivElement>(null);
const { width } = useContainerDimensions(componentRef);
return (
<div className="row justify-content-center" ref={componentRef}>
{galleries.map((gallery) => (
<GalleryCard
key={gallery.id}
containerWidth={width}
gallery={gallery}
zoomIndex={zoomIndex}
selecting={selectedIds.size > 0}
selected={selectedIds.has(gallery.id)}
onSelectedChanged={(selected: boolean, shiftKey: boolean) =>
onSelectChange(gallery.id, selected, shiftKey)
}
/>
))}
</div>
);
};