From e915ded2dead947662f772a4639fbf0b59afbc0f Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 23 Dec 2024 16:18:12 +0530 Subject: [PATCH] fit in --- web/packages/new/photos/pages/duplicates.tsx | 69 +++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/web/packages/new/photos/pages/duplicates.tsx b/web/packages/new/photos/pages/duplicates.tsx index 3f1c0140ae..d8695e5eb1 100644 --- a/web/packages/new/photos/pages/duplicates.tsx +++ b/web/packages/new/photos/pages/duplicates.tsx @@ -24,13 +24,23 @@ import { Typography, } from "@mui/material"; import { useRouter } from "next/router"; -import React, { memo, useCallback, useEffect, useReducer } from "react"; +import React, { + memo, + useCallback, + useEffect, + useMemo, + useReducer, +} from "react"; import Autosizer from "react-virtualized-auto-sizer"; import { areEqual, FixedSizeList, type ListChildComponentProps, } from "react-window"; +import { + computeThumbnailGridLayoutParams, + type ThumbnailGridLayoutParams, +} from "../components/utils/thumbnail-grid-layout"; import { deduceDuplicates, type DuplicateGroup } from "../services/dedup"; import { useAppContext } from "../types/context"; @@ -374,7 +384,18 @@ const Duplicates: React.FC = ({ return ( - + + {({ width, height }) => ( + + )} + @@ -384,6 +405,14 @@ const Duplicates: React.FC = ({ }; interface DuplicatesListProps { + /** + * The width (px) that the list should size itself to. + */ + width: number; + /** + * The height (px) that the list should size itself to. + */ + height: number; /** * Groups of duplicates. Guaranteed to be non-empty. */ @@ -395,29 +424,37 @@ interface DuplicatesListProps { onToggleSelection: (index: number) => void; } +type DuplicatesListItemData = Pick< + DuplicatesListProps, + "duplicateGroups" | "onToggleSelection" +> & { + layoutParams: ThumbnailGridLayoutParams; +}; + const DuplicatesList: React.FC = ({ + width, + height, duplicateGroups, onToggleSelection, }) => { + const layoutParams = useMemo( + () => computeThumbnailGridLayoutParams(width), + [width], + ); + const itemCount = duplicateGroups.length; const itemSize = 100; + const itemData = { layoutParams, duplicateGroups, onToggleSelection }; return ( - - {({ height, width }) => ( - - {ListItem} - - )} - + + {ListItem} + ); }; -const ListItem: React.FC> = memo( - ({ index, style, data }) => { +const ListItem: React.FC> = + memo(({ index, style, data }) => { const { duplicateGroups, onToggleSelection } = data; const duplicateGroup = duplicateGroups[index]!; @@ -461,9 +498,7 @@ const ListItem: React.FC> = memo( ); - }, - areEqual, -); + }, areEqual); const ItemGrid = styled("div")` display: grid;