π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Derive
Manav Rathif9a29a9e1714
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 204d378e15..6cf83e16e0 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -264,9 +264,6 @@ export default function Gallery() {const [emailList, setEmailList] = useState<string[]>(null);const [activeCollectionID, setActiveCollectionID] =useState<number>(undefined);- const [hiddenFileIds, setHiddenFileIds] = useState<Set<number>>(- new Set<number>(),- );const [fixCreationTimeView, setFixCreationTimeView] = useState(false);const [fixCreationTimeAttributes, setFixCreationTimeAttributes] =useState<FixCreationTimeAttributes>(null);@@ -349,7 +346,8 @@ export default function Gallery() {const files = state.files;const hiddenFiles = state.hiddenFiles;const trashedFiles = state.trashedFiles;- const archivedCollections = state.archivedCollectionIDs;+ const archivedCollectionIDs = state.archivedCollectionIDs;+ const hiddenFileIDs = state.hiddenFileIDs;if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) {console.log("render", { collections, hiddenCollections, files });@@ -446,9 +444,8 @@ export default function Gallery() {return;}const {- favFileIDs,+ favoriteFileIDs,defaultHiddenCollectionIDs,- hiddenFileIds,mergedCollectionSummaries,hiddenCollectionSummaries,} = setDerivativeState(@@ -458,15 +455,14 @@ export default function Gallery() {files,trashedFiles,hiddenFiles,- archivedCollections,+ archivedCollectionIDs,);// This wait(0) is a hack, but it is not a new one, this merely retains// the behaviour of the old code. Without this, the "Nothing here"// message flashes for a second.wait(0).then(() => {- dispatch({ type: "setDerived", favFileIDs });+ dispatch({ type: "setDerived", favoriteFileIDs });setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);- setHiddenFileIds(hiddenFileIds);setCollectionSummaries(mergedCollectionSummaries);setHiddenCollectionSummaries(hiddenCollectionSummaries);});@@ -556,7 +552,7 @@ export default function Gallery() {!user ||!trashedFiles ||!hiddenFiles ||- !archivedCollections+ !archivedCollectionIDs) {dispatch({type: "set",@@ -643,7 +639,7 @@ export default function Gallery() {}// archived collections files can only be seen in their respective collection- if (archivedCollections.has(item.collectionID)) {+ if (archivedCollectionIDs.has(item.collectionID)) {if (activeCollectionID === item.collectionID) {return true;} else {@@ -674,7 +670,7 @@ export default function Gallery() {// ALL SECTION - show all filesif (activeCollectionID === ALL_SECTION) {// show all files except the ones in hidden collections- if (hiddenFileIds.has(item.id)) {+ if (hiddenFileIDs.has(item.id)) {return false;} else {return true;@@ -708,10 +704,10 @@ export default function Gallery() {hiddenFiles,tempDeletedFileIds,tempHiddenFileIds,- hiddenFileIds,+ hiddenFileIDs,selectedSearchOption,activeCollectionID,- archivedCollections,+ archivedCollectionIDs,peopleState,activePersonID,]);@@ -1126,8 +1122,8 @@ export default function Gallery() {);const refreshFavItemIds = async () => {- const favFileIDs = await getFavItemIds(files);- dispatch({ type: "setFavorites", favFileIDs });+ const favoriteFileIDs = await getFavItemIds(files);+ dispatch({ type: "refreshFavorites", favoriteFileIDs });};if (!collectionSummaries || !filteredData) {@@ -1317,7 +1313,7 @@ export default function Gallery() {modePlus={isInSearchMode ? "search" : barMode}files={filteredData}syncWithRemote={syncWithRemote}- favItemIds={state.favFileIDs}+ favItemIds={state.favoriteFileIDs}setSelected={setSelected}selected={selected}tempDeletedFileIds={tempDeletedFileIds}diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex b81b3d2616..f2a62706af 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -91,10 +91,14 @@ export interface GalleryState {* Collection IDs of archived collections.*/archivedCollectionIDs: Set<number>;+ /**+ * File IDs of the files that the user has hidden.+ */+ hiddenFileIDs: Set<number>;/*** File IDs of all the files that the user has marked as a favorite.*/- favFileIDs: Set<number>;+ favoriteFileIDs: Set<number>;/*--< UI state >--*/@@ -129,7 +133,7 @@ export type GalleryAction =| { activePerson: Person | undefined; people: Person[] }| undefined;}- | { type: "setDerived"; favFileIDs: Set<number> }+ | { type: "setDerived"; favoriteFileIDs: Set<number> }| {type: "setNormalCollections";collections: Collection[];@@ -145,7 +149,7 @@ export type GalleryAction =| { type: "resetHiddenFiles"; hiddenFiles: EnteFile[] }| { type: "fetchHiddenFiles"; hiddenFiles: EnteFile[] }| { type: "setTrashedFiles"; trashedFiles: EnteFile[] }- | { type: "setFavorites"; favFileIDs: Set<number> };+ | { type: "refreshFavorites"; favoriteFileIDs: Set<number> };const initialGalleryState: GalleryState = {user: undefined,@@ -157,7 +161,8 @@ const initialGalleryState: GalleryState = {trashedFiles: [],filteredData: [],archivedCollectionIDs: new Set(),- favFileIDs: new Set(),+ hiddenFileIDs: new Set(),+ favoriteFileIDs: new Set(),activePerson: undefined,people: [],};@@ -184,7 +189,8 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (files: action.files,hiddenFiles: action.hiddenFiles,trashedFiles: action.trashedFiles,- archivedCollectionIDs: getArchivedCollectionIDs(collections),+ archivedCollectionIDs: deriveArchivedCollectionIDs(collections),+ hiddenFileIDs: deriveHiddenFileIDs(action.hiddenFiles),};}case "set":@@ -197,13 +203,13 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (case "setDerived":return {...state,- favFileIDs: action.favFileIDs,+ favoriteFileIDs: action.favoriteFileIDs,};case "setNormalCollections":return {...state,collections: action.collections,- archivedCollectionIDs: getArchivedCollectionIDs(+ archivedCollectionIDs: deriveArchivedCollectionIDs(action.collections,),};@@ -212,7 +218,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (...state,collections: action.collections,hiddenCollections: action.hiddenCollections,- archivedCollectionIDs: getArchivedCollectionIDs(+ archivedCollectionIDs: deriveArchivedCollectionIDs(action.collections,),};@@ -235,27 +241,33 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (...state,files: sortFiles([...state.files, action.file]),};- case "resetHiddenFiles":+ case "resetHiddenFiles": {+ const hiddenFiles = sortFiles(mergeMetadata(action.hiddenFiles));return {...state,- hiddenFiles: sortFiles(mergeMetadata(action.hiddenFiles)),+ hiddenFiles,+ hiddenFileIDs: deriveHiddenFileIDs(hiddenFiles),};- case "fetchHiddenFiles":+ }+ case "fetchHiddenFiles": {+ const hiddenFiles = sortFiles(+ mergeMetadata(+ getLatestVersionFiles([+ ...state.hiddenFiles,+ ...action.hiddenFiles,+ ]),+ ),+ );return {...state,- hiddenFiles: sortFiles(- mergeMetadata(- getLatestVersionFiles([- ...state.hiddenFiles,- ...action.hiddenFiles,- ]),- ),- ),+ hiddenFiles,+ hiddenFileIDs: deriveHiddenFileIDs(hiddenFiles),};+ }case "setTrashedFiles":return { ...state, trashedFiles: action.trashedFiles };- case "setFavorites":- return { ...state, favFileIDs: action.favFileIDs };+ case "refreshFavorites":+ return { ...state, favoriteFileIDs: action.favoriteFileIDs };}};@@ -271,23 +283,10 @@ export const setDerivativeState = (hiddenFiles: EnteFile[],archivedCollections: Set<number>,) => {- let favFileIDs = new Set<number>();- for (const collection of collections) {- if (collection.type === CollectionType.favorites) {- favFileIDs = new Set(- files- .filter((file) => file.collectionID === collection.id)- .map((file): number => file.id),- );- break;- }- }+ const favoriteFileIDs = deriveFavoriteFileIDs(collections, files);const defaultHiddenCollectionIDs =getDefaultHiddenCollectionIDs(hiddenCollections);// setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);- const hiddenFileIds = new Set<number>(hiddenFiles.map((f) => f.id));- // TODO: Move to reducer- // setHiddenFileIds(hiddenFileIds);const collectionSummaries = getCollectionSummaries(user,collections,@@ -318,9 +317,8 @@ export const setDerivativeState = (// setHiddenCollectionSummaries(hiddenCollectionSummaries);return {- favFileIDs,+ favoriteFileIDs,defaultHiddenCollectionIDs,- hiddenFileIds,mergedCollectionSummaries,hiddenCollectionSummaries,};@@ -349,7 +347,35 @@ export const uniqueFilesByID = (files: EnteFile[]) => {});};-const getArchivedCollectionIDs = (collections: Collection[]) =>+/**+ * Helper function to compute favorite file IDs from its dependencies.+ */+const deriveFavoriteFileIDs = (+ collections: Collection[],+ files: EnteFile[],+): Set<number> => {+ for (const collection of collections) {+ if (collection.type === CollectionType.favorites) {+ return new Set(+ files+ .filter((file) => file.collectionID === collection.id)+ .map((file): number => file.id),+ );+ }+ }+ return new Set();+};++/**+ * Helper function to compute hidden file IDs from its dependencies.+ */+const deriveHiddenFileIDs = (hiddenFiles: EnteFile[]) =>+ new Set<number>(hiddenFiles.map((f) => f.id));++/**+ * Helper function to compute archived collection IDs from its dependencies.+ */+const deriveArchivedCollectionIDs = (collections: Collection[]) =>new Set<number>(collections.filter(isArchivedCollection)