From 488402156ff037112a9fe243798db18bbf1dc31a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 21 Feb 2025 15:45:46 +0530 Subject: [PATCH] take 1 --- .../photos/src/components/PhotoList/index.tsx | 4 +- web/apps/photos/src/utils/photoFrame/index.ts | 45 +++++++++---------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsx index 72b15ac75a..b83fe3bd4b 100644 --- a/web/apps/photos/src/components/PhotoList/index.tsx +++ b/web/apps/photos/src/components/PhotoList/index.tsx @@ -828,9 +828,7 @@ export function PhotoList({ console.timeEnd("c2"); console.time("c3"); - filesOnADay.forEach((file) => { - handleSelect(file)(isDateSelected); - }); + handleSelect(filesOnADay)(isDateSelected); console.timeEnd("c3"); }; diff --git a/web/apps/photos/src/utils/photoFrame/index.ts b/web/apps/photos/src/utils/photoFrame/index.ts index 06d8d41207..d549be0262 100644 --- a/web/apps/photos/src/utils/photoFrame/index.ts +++ b/web/apps/photos/src/utils/photoFrame/index.ts @@ -143,7 +143,7 @@ export const handleSelectCreatorMulti = activeCollectionID: number, activePersonID: string | undefined, ) => - ({ id, ownerID }: { id: number; ownerID: number }) => + (files: { id: number; ownerID: number }[]) => (checked: boolean) => { setSelected((selected) => { if (!mode) { @@ -224,35 +224,30 @@ export const handleSelectCreatorMulti = ? { mode, personID: activePersonID! } : { mode, collectionID: activeCollectionID! }; - const handleCounterChange = (count: number) => { - if (selected[id] === checked) { - return count; - } - if (checked) { - return count + 1; - } else { - return count - 1; - } - }; + const newSelected = { ...selected }; + let newCount = selected.count; + let newOwnCount = selected.ownCount; - const handleAllCounterChange = () => { - if (ownerID === userID) { - return { - ownCount: handleCounterChange(selected.ownCount), - count: handleCounterChange(selected.count), - }; - } else { - return { - count: handleCounterChange(selected.count), - }; + if (checked) { + for (const file of files) { + newSelected[file.id] = true; + newCount++; + if (file.ownerID === userID) newOwnCount++; } - }; + } else { + for (const file of files) { + newSelected[file.id] = false; + newCount--; + if (file.ownerID === userID) newOwnCount--; + } + } + return { - ...selected, - [id]: checked, + ...newSelected, + count: newCount, + ownCount: newOwnCount, collectionID: activeCollectionID, context: newContext, - ...handleAllCounterChange(), }; }); };