π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Investigate speeding up the checkbox action too
Manav Rathid2dd08391af9
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsxindex 1445ca170b..12aaf0f4e7 100644--- a/web/apps/photos/src/components/PhotoFrame.tsx+++ b/web/apps/photos/src/components/PhotoFrame.tsx@@ -70,8 +70,15 @@ export type DisplayFile = EnteFile & {conversionFailed?: boolean;canForceConvert?: boolean;/**- * The formatted date string under which this file should be grouped in the- * gallery listing.+ * [Note: Timeline date string]+ *+ * The timeline date string is a formatted date string under which a+ * particular file should be grouped in the gallery listing. e.g. "Today",+ * "Yesterday", "Fri, 21 Feb" etc.+ *+ * All files which have the same timelineDateString will be grouped under a+ * single section in the gallery listing, prefixed by the timelineDateString+ * itself, and a checkbox to select all files on that date.*/timelineDateString?: string;};@@ -674,6 +681,9 @@ const updateDisplayFileSource = (}};+/**+ * See: [Note: Timeline date string]+ */const fileTimelineDateString = (item: EnteFile) => {const date = new Date(item.metadata.creationTime / 1000);return isSameDay(date, new Date())diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsxindex 0fde64eadd..da1519d58a 100644--- a/web/apps/photos/src/components/PhotoList/index.tsx+++ b/web/apps/photos/src/components/PhotoList/index.tsx@@ -273,7 +273,11 @@ export function PhotoList({const shouldRefresh = useRef(false);const listRef = useRef(null);- const [checkedDates, setCheckedDates] = useState({});+ // Timeline date strings for which all photos have been selected.+ //+ // See: [Note: Timeline date string]+ const [checkedTimelineDateStrings, setCheckedTimelineDateStrings] =+ useState(new Set());const fittableColumns = getFractionFittableColumns(width);let columns = Math.floor(fittableColumns);@@ -757,20 +761,34 @@ export function PhotoList({localSelectedFiles.map((item) => item.timelineDateString),); // to get file's date which were manually selected- unselectedDates.forEach((date) => {- setCheckedDates((prev) => ({- ...prev,- [date]: false,- })); // To uncheck select all checkbox if any of the file on the date is unselected- });+ setCheckedTimelineDateStrings((prev) => {+ console.time("s1");++ const checked = new Set(prev);+ // Uncheck the "Select all" checkbox if any of the files on the date+ // is unselected.+ unselectedDates.forEach((date) => checked.delete(date));+ // Check the "Select all" checkbox if all of the files on a date are+ // selected.+ localSelectedDates.forEach((date) => checked.add(date));+ console.timeEnd("s1");- localSelectedDates.forEach((date) => {- setCheckedDates((prev) => ({- ...prev,- [date]: true,- }));- // To check select all checkbox if all of the files on the date is selected manually+ return checked;});+ // unselectedDates.forEach((date) => {+ // setCheckedDates((prev) => ({+ // ...prev,+ // [date]: false,+ // }));+ // });++ // localSelectedDates.forEach((date) => {+ // setCheckedDates((prev) => ({+ // ...prev,+ // [date]: true,+ // }));++ // });console.timeEnd("t6");}, [galleryContext.selectedFile]);@@ -783,21 +801,40 @@ export function PhotoList({);const onChangeSelectAllCheckBox = (date: string) => {- const dates = { ...checkedDates, [date]: !checkedDates[date] };- const isDateSelected = !checkedDates[date];+ console.time("c1");++ // const dates = { ...checkedDates, [date]: !checkedDates[date] };+ const next = new Set(checkedTimelineDateStrings);+ let isDateSelected: boolean;+ if (!next.has(date)) {+ next.add(date);+ isDateSelected = true;+ } else {+ next.delete(date);+ isDateSelected = false;+ }+ // const isDateSelected = !checkedDates[date];- setCheckedDates(dates);+ // setCheckedDates(dates);+ setCheckedTimelineDateStrings(next);+ console.timeEnd("c1");+ console.time("c2");const filesOnADay = displayFiles?.filter((item) => item.timelineDateString === date,); // all files on a checked/unchecked day+ console.timeEnd("c2");+ console.time("c3");+filesOnADay.forEach((file) => {handleSelect(file.id,file.ownerID === galleryContext?.user?.id,)(isDateSelected);});++ console.timeEnd("c3");};const renderListItem = (@@ -817,7 +854,10 @@ export function PhotoList({<Checkboxkey={item.date}name={item.date}- checked={!!checkedDates[item.date]}+ // checked={!!checkedDates[item.date]}+ checked={checkedTimelineDateStrings.has(+ item.date,+ )}onChange={() =>onChangeSelectAllCheckBox(item.date)}@@ -836,7 +876,10 @@ export function PhotoList({<Checkboxkey={listItem.date}name={listItem.date}- checked={!!checkedDates[listItem.date]}+ // checked={!!checkedDates[listItem.date]}+ checked={checkedTimelineDateStrings.has(+ listItem.date,+ )}onChange={() =>onChangeSelectAllCheckBox(listItem.date)}