π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(large-files):persist-file-selection-across-filter-changes
Aswin Asok160d636b7c88
diff --git a/web/apps/photos/src/pages/large-files.tsx b/web/apps/photos/src/pages/large-files.tsxindex 0d58dff91c..c8e35a1a90 100644--- a/web/apps/photos/src/pages/large-files.tsx+++ b/web/apps/photos/src/pages/large-files.tsx@@ -499,7 +499,7 @@ const GridItem: React.FC<GridItemProps> = memo(({ item, onToggle, onOpen }) => {isLongPress.current = false;longPressTimer.current = setTimeout(() => {isLongPress.current = true;- onToggle();+ onOpen();}, LONG_PRESS_DURATION);};@@ -520,8 +520,8 @@ const GridItem: React.FC<GridItemProps> = memo(({ item, onToggle, onOpen }) => {const handleClick = () => {if (isLongPress.current) return;- // On mobile, if item is selected, tap to deselect- if (isTouchDevice && checked) {+ // On mobile, tap to toggle selection; on desktop, tap to open+ if (isTouchDevice) {onToggle();} else {onOpen();@@ -591,7 +591,10 @@ const BottomBar: React.FC<BottomBarProps> = ({}}><FocusVisibleButton- sx={{ px: 5 }}+ sx={{+ width: { xs: 125, sm: 140 },+ fontSize: { xs: "0.85rem", sm: "0.9rem" },+ }}disabled={deleteProgress !== undefined}onClick={hasSelection ? onDeselectAll : onSelectAll}>@@ -621,38 +624,53 @@ const DeleteButton: React.FC<DeleteButtonProps> = ({selectedSize,deleteProgress,onDeleteFiles,-}) => (- <FocusVisibleButton- sx={{- px: 3,- "&.Mui-disabled": {- backgroundColor: "rgba(255, 255, 255, 0.12)",- color: "rgba(255, 255, 255, 0.5)",- },- }}- disabled={selectedCount == 0 || deleteProgress !== undefined}- color="critical"- onClick={onDeleteFiles}- >- {deleteProgress !== undefined ? (- <LinearProgress- sx={{ borderRadius: "4px", width: "100%" }}- variant={deleteProgress === 0 ? "indeterminate" : "determinate"}- value={deleteProgress}- color="inherit"- />- ) : (- <Stack direction="row" sx={{ gap: 1, alignItems: "center" }}>- <Typography>- {t("delete_files_button", { count: selectedCount })}- </Typography>- <Typography variant="small" fontWeight="regular">- ({formattedByteSize(selectedSize)})- </Typography>- </Stack>- )}- </FocusVisibleButton>-);+}) => {+ const isDeleting = deleteProgress !== undefined;++ return (+ <FocusVisibleButton+ sx={{+ px: { xs: 2, sm: 3 },+ width: { xs: 220, sm: 260 },+ minHeight: { xs: 42, sm: 44 },+ fontSize: { xs: "0.85rem", sm: "0.9rem" },+ "&.Mui-disabled": isDeleting+ ? {+ // Keep critical color during deletion+ backgroundColor: "critical.main",+ color: "critical.contrastText",+ }+ : {+ backgroundColor: "rgba(255, 255, 255, 0.12)",+ color: "rgba(255, 255, 255, 0.5)",+ },+ }}+ disabled={selectedCount == 0 || isDeleting}+ color="critical"+ onClick={onDeleteFiles}+ >+ {isDeleting ? (+ <LinearProgress+ sx={{ borderRadius: "4px", width: "100%" }}+ variant={+ deleteProgress === 0 ? "indeterminate" : "determinate"+ }+ value={deleteProgress}+ color="inherit"+ />+ ) : (+ <Stack direction="row" sx={{ gap: 1, alignItems: "center" }}>+ <Typography>+ {t("delete_files_button", { count: selectedCount })}+ </Typography>+ <Typography variant="small" fontWeight="regular">+ ({formattedByteSize(selectedSize)})+ </Typography>+ </Stack>+ )}+ </FocusVisibleButton>+ );+};// --- Styled Components ---diff --git a/web/packages/new/photos/services/large-files.ts b/web/packages/new/photos/services/large-files.tsindex 438150705e..69c309d7c0 100644--- a/web/packages/new/photos/services/large-files.ts+++ b/web/packages/new/photos/services/large-files.ts@@ -189,6 +189,11 @@ export interface LargeFilesState {* percentage (a number between 0 and 100).*/deleteProgress: number | undefined;+ /**+ * Set of selected file IDs (the underlying EnteFile.id).+ * Used to persist selection across filter changes.+ */+ selectedFileIDs: Set<number>;}/**@@ -219,6 +224,7 @@ export const largeFilesInitialState: LargeFilesState = {selectedCount: 0,selectedSize: 0,deleteProgress: undefined,+ selectedFileIDs: new Set(),};/**@@ -234,7 +240,12 @@ export const largeFilesReducer = (case "analysisFailed":return { ...state, analysisStatus: "failed" };case "analysisCompleted": {- const largeFiles = action.largeFiles;+ // Restore selection state from selectedFileIDs+ const selectedFileIDs = state.selectedFileIDs;+ const largeFiles = action.largeFiles.map((item) => ({+ ...item,+ isSelected: selectedFileIDs.has(item.file.id),+ }));const { selectedCount, selectedSize } =computeSelectedCountAndSize(largeFiles);return {@@ -247,11 +258,12 @@ export const largeFilesReducer = (}case "changeFilter": {- // Reset state when filter changes, will trigger re-analysis.+ // Preserve selectedFileIDs when filter changesreturn {...largeFilesInitialState,filter: action.filter,sortOrder: state.sortOrder,+ selectedFileIDs: state.selectedFileIDs,};}@@ -268,9 +280,22 @@ export const largeFilesReducer = (const largeFiles = [...state.largeFiles];const item = largeFiles[action.index]!;item.isSelected = !item.isSelected;+ // Update selectedFileIDs+ const selectedFileIDs = new Set(state.selectedFileIDs);+ if (item.isSelected) {+ selectedFileIDs.add(item.file.id);+ } else {+ selectedFileIDs.delete(item.file.id);+ }const { selectedCount, selectedSize } =computeSelectedCountAndSize(largeFiles);- return { ...state, largeFiles, selectedCount, selectedSize };+ return {+ ...state,+ largeFiles,+ selectedCount,+ selectedSize,+ selectedFileIDs,+ };}case "deselectAll": {@@ -278,7 +303,13 @@ export const largeFilesReducer = (...item,isSelected: false,}));- return { ...state, largeFiles, selectedCount: 0, selectedSize: 0 };+ return {+ ...state,+ largeFiles,+ selectedCount: 0,+ selectedSize: 0,+ selectedFileIDs: new Set(),+ };}case "selectAll": {@@ -286,9 +317,18 @@ export const largeFilesReducer = (...item,isSelected: true,}));+ const selectedFileIDs = new Set(+ largeFiles.map((item) => item.file.id),+ );const { selectedCount, selectedSize } =computeSelectedCountAndSize(largeFiles);- return { ...state, largeFiles, selectedCount, selectedSize };+ return {+ ...state,+ largeFiles,+ selectedCount,+ selectedSize,+ selectedFileIDs,+ };}case "delete":@@ -301,9 +341,19 @@ export const largeFilesReducer = (return { ...state, deleteProgress: undefined };case "deleteCompleted": {+ const removedFileIDs = new Set(+ state.largeFiles+ .filter(({ id }) => action.removedIDs.has(id))+ .map(({ file }) => file.id),+ );const largeFiles = state.largeFiles.filter(({ id }) => !action.removedIDs.has(id),);+ const selectedFileIDs = new Set(+ [...state.selectedFileIDs].filter(+ (id) => !removedFileIDs.has(id),+ ),+ );const { selectedCount, selectedSize } =computeSelectedCountAndSize(largeFiles);return {@@ -312,6 +362,7 @@ export const largeFilesReducer = (selectedCount,selectedSize,deleteProgress: undefined,+ selectedFileIDs,};}}