Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move

Manav Rathi1479638f0869
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index f6f1832a47..c298eeb0aa 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -178,7 +178,7 @@ export const GalleryContext = createContext<GalleryContextType>(
/**
* The default view for logged in users.
*
- * I heard you like ascii art.
+ * I heard you like ASCII art.
*
* Navbar / Search ^
* --------------------- |
@@ -190,8 +190,6 @@ export const GalleryContext = createContext<GalleryContextType>(
*/
export default function Gallery() {
const [state, dispatch] = useGalleryReducer();
- const [defaultHiddenCollectionIDs, setDefaultHiddenCollectionIDs] =
- useState<Set<number>>();
const [isFirstLoad, setIsFirstLoad] = useState(false);
const [selected, setSelected] = useState<SelectedState>({
@@ -346,6 +344,7 @@ export default function Gallery() {
const hiddenFiles = state.hiddenFiles;
const trashedFiles = state.trashedFiles;
const archivedCollectionIDs = state.archivedCollectionIDs;
+ const defaultHiddenCollectionIDs = state.defaultHiddenCollectionIDs;
const hiddenFileIDs = state.hiddenFileIDs;
if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) {
@@ -442,24 +441,20 @@ export default function Gallery() {
if (!user || !files || !collections || !hiddenFiles || !trashedFiles) {
return;
}
- const {
- defaultHiddenCollectionIDs,
- mergedCollectionSummaries,
- hiddenCollectionSummaries,
- } = setDerivativeState(
- user,
- collections,
- hiddenCollections,
- files,
- trashedFiles,
- hiddenFiles,
- archivedCollectionIDs,
- );
+ const { mergedCollectionSummaries, hiddenCollectionSummaries } =
+ setDerivativeState(
+ user,
+ collections,
+ hiddenCollections,
+ files,
+ trashedFiles,
+ hiddenFiles,
+ 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(() => {
- setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);
setCollectionSummaries(mergedCollectionSummaries);
setHiddenCollectionSummaries(hiddenCollectionSummaries);
});
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index cb7327d7c7..91c36a1cac 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -91,6 +91,10 @@ export interface GalleryState {
* Collection IDs of archived collections.
*/
archivedCollectionIDs: Set<number>;
+ /**
+ * Collection IDs of default hidden collections.
+ */
+ defaultHiddenCollectionIDs: Set<number>;
/**
* File IDs of the files that the user has hidden.
*/
@@ -160,6 +164,7 @@ const initialGalleryState: GalleryState = {
trashedFiles: [],
filteredData: [],
archivedCollectionIDs: new Set(),
+ defaultHiddenCollectionIDs: new Set(),
hiddenFileIDs: new Set(),
favoriteFileIDs: new Set(),
activePerson: undefined,
@@ -189,6 +194,8 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenFiles: action.hiddenFiles,
trashedFiles: action.trashedFiles,
archivedCollectionIDs: deriveArchivedCollectionIDs(collections),
+ defaultHiddenCollectionIDs:
+ deriveDefaultHiddenCollectionIDs(hiddenCollections),
hiddenFileIDs: deriveHiddenFileIDs(action.hiddenFiles),
favoriteFileIDs: deriveFavoriteFileIDs(
collections,
@@ -227,6 +234,9 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
archivedCollectionIDs: deriveArchivedCollectionIDs(
action.collections,
),
+ defaultHiddenCollectionIDs: deriveDefaultHiddenCollectionIDs(
+ action.hiddenCollections,
+ ),
favoriteFileIDs: deriveFavoriteFileIDs(
action.collections,
state.files,
@@ -309,9 +319,6 @@ export const setDerivativeState = (
hiddenFiles: EnteFile[],
archivedCollections: Set<number>,
) => {
- const defaultHiddenCollectionIDs =
- getDefaultHiddenCollectionIDs(hiddenCollections);
- // setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);
const collectionSummaries = getCollectionSummaries(
user,
collections,
@@ -342,7 +349,6 @@ export const setDerivativeState = (
// setHiddenCollectionSummaries(hiddenCollectionSummaries);
return {
- defaultHiddenCollectionIDs,
mergedCollectionSummaries,
hiddenCollectionSummaries,
};
@@ -372,7 +378,30 @@ export const uniqueFilesByID = (files: EnteFile[]) => {
};
/**
- * Helper function to compute favorite file IDs from its dependencies.
+ * Helper function to compute archived collection IDs from their dependencies.
+ */
+const deriveArchivedCollectionIDs = (collections: Collection[]) =>
+ new Set<number>(
+ collections
+ .filter(isArchivedCollection)
+ .map((collection) => collection.id),
+ );
+
+/**
+ * Helper function to compute the default hidden collection IDs from theirq
+ * dependencies.
+ */
+const deriveDefaultHiddenCollectionIDs = (hiddenCollections: Collection[]) =>
+ getDefaultHiddenCollectionIDs(hiddenCollections);
+
+/**
+ * Helper function to compute hidden file IDs from their dependencies.
+ */
+const deriveHiddenFileIDs = (hiddenFiles: EnteFile[]) =>
+ new Set<number>(hiddenFiles.map((f) => f.id));
+
+/**
+ * Helper function to compute favorite file IDs from their dependencies.
*/
const deriveFavoriteFileIDs = (
collections: Collection[],
@@ -390,22 +419,6 @@ const deriveFavoriteFileIDs = (
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)
- .map((collection) => collection.id),
- );
-
function getCollectionSummaries(
user: User,
collections: Collection[],