π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refresh list on width and sort order changes
Manav Rathi7602d48bd96d
diff --git a/web/packages/new/photos/pages/duplicates.tsx b/web/packages/new/photos/pages/duplicates.tsxindex 0ef57543fe..f36c147a16 100644--- a/web/packages/new/photos/pages/duplicates.tsx+++ b/web/packages/new/photos/pages/duplicates.tsx@@ -91,6 +91,7 @@ const Page: React.FC = () => {return (<DuplicatesduplicateGroups={state.duplicateGroups}+ sortOrder={state.sortOrder}onToggleSelection={(index) =>dispatch({ type: "toggleSelection", index })}@@ -383,12 +384,13 @@ const NoDuplicatesFound: React.FC = () => (type DuplicatesProps = Pick<DuplicatesListProps,- "duplicateGroups" | "onToggleSelection"+ "duplicateGroups" | "sortOrder" | "onToggleSelection"> &DeduplicateButtonProps;const Duplicates: React.FC<DuplicatesProps> = ({duplicateGroups,+ sortOrder,onToggleSelection,...deduplicateButtonProps}) => (@@ -401,6 +403,7 @@ const Duplicates: React.FC<DuplicatesProps> = ({width,height,duplicateGroups,+ sortOrder,onToggleSelection,}}/>@@ -426,6 +429,10 @@ interface DuplicatesListProps {* Groups of duplicates. Guaranteed to be non-empty.*/duplicateGroups: DuplicateGroup[];+ /**+ * The current {@link SortOrder} that is being used for sorting {@link duplicateGroups}.+ */+ sortOrder: SortOrder;/*** Called when the user toggles the selection for the duplicate group at the* given {@link index}.@@ -444,6 +451,7 @@ const DuplicatesList: React.FC<DuplicatesListProps> = ({width,height,duplicateGroups,+ sortOrder,onToggleSelection,}) => {const layoutParams = useMemo(@@ -451,6 +459,7 @@ const DuplicatesList: React.FC<DuplicatesListProps> = ({[width],);+ const itemData = { layoutParams, duplicateGroups, onToggleSelection };const itemCount = duplicateGroups.length;const itemSize = (index: number) => {// The height of the header is driven by the height of the Checkbox,@@ -467,10 +476,18 @@ const DuplicatesList: React.FC<DuplicatesListProps> = ({return fixedHeight + rowCount * rowHeight;};- const itemData = { layoutParams, duplicateGroups, onToggleSelection };+ const itemKey = (index: number, itemData: DuplicatesListItemData) =>+ itemData.duplicateGroups[index]!.id;++ // Derive a key based on aspects whose change should cause the list to be+ // recreated. This is the easiest way I've found to get react-window to+ // invalidate `itemSize` values when, say, the width changes.+ const key = `${width}-${sortOrder}`;return (- <VariableSizeList {...{ height, width, itemCount, itemSize, itemData }}>+ <VariableSizeList+ {...{ key, height, width, itemData, itemCount, itemSize, itemKey }}+ >{ListItem}</VariableSizeList>);diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.tsindex b5bd842a62..8b87e95eb3 100644--- a/web/packages/new/photos/services/dedup.ts+++ b/web/packages/new/photos/services/dedup.ts@@ -2,11 +2,18 @@ import type { EnteFile } from "@/media/file";import { createCollectionNameByID } from "./collection";import { getLocalCollections } from "./collections";import { getLocalFiles, uniqueFilesByID } from "./files";+import { newID } from "@/base/id";/*** A group of duplicates as shown in the UI.*/export interface DuplicateGroup {+ /**+ * A nanoid for this group.+ *+ * This can be used as the key when rendering the group in a list.+ */+ id: string;/*** Files which our algorithm has determined to be duplicates of each other.*@@ -111,6 +118,7 @@ export const deduceDuplicates = async () => {.filter((item) => !!item);if (items.length < 2) continue;duplicateGroups.push({+ id: newID("dg_"),items,itemSize: size,prunableCount: duplicates.length - 1,