Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reactive

Manav Rathi53468c9c3e64
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 9fe1c45785..ae11448271 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -25,9 +25,10 @@ import {
isIncomingShare,
TRASH_SECTION,
} from "../../services/collection";
-import type {
- CollectionSummary,
- CollectionSummaryType,
+import {
+ CollectionSummaryID,
+ type CollectionSummary,
+ type CollectionSummaryType,
} from "../../services/collection-summary";
import {
createFileCollectionIDs,
@@ -251,6 +252,17 @@ export interface GalleryState {
* collections.
*/
hiddenCollectionSummaries: Map<number, CollectionSummary>;
+ /**
+ * The ID of the collection summary that should be shown when the user
+ * navigates to the uncategorized section.
+ *
+ * This will be either the ID of the user's uncategorized collection, if one
+ * has already been created, otherwise it will be the predefined
+ * {@link CollectionSummaryID.uncategorizedPlaceholder}.
+ *
+ * See: [Note: Uncategorized placeholder]
+ */
+ uncategorizedCollectionSummaryID: number;
/*--< In-flight updates >--*/
@@ -473,6 +485,8 @@ const initialGalleryState: GalleryState = {
fileNormalCollectionIDs: new Map(),
normalCollectionSummaries: new Map(),
hiddenCollectionSummaries: new Map(),
+ uncategorizedCollectionSummaryID:
+ CollectionSummaryID.uncategorizedPlaceholder,
tempDeletedFileIDs: new Set(),
tempHiddenFileIDs: new Set(),
pendingFavoriteUpdates: new Set(),
@@ -565,6 +579,8 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenCollections,
hiddenFiles,
),
+ uncategorizedCollectionSummaryID:
+ deriveUncategorizedCollectionSummaryID(normalCollections),
view,
});
}
@@ -627,6 +643,8 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
collectionNameByID: createCollectionNameByID(collections),
normalCollectionSummaries,
hiddenCollectionSummaries,
+ uncategorizedCollectionSummaryID:
+ deriveUncategorizedCollectionSummaryID(normalCollections),
selectedCollectionSummaryID,
pendingSearchSuggestions:
enqueuePendingSearchSuggestionsIfNeeded(
@@ -681,6 +699,8 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
normalCollections.concat(state.hiddenCollections),
),
normalCollectionSummaries,
+ uncategorizedCollectionSummaryID:
+ deriveUncategorizedCollectionSummaryID(normalCollections),
selectedCollectionSummaryID,
pendingSearchSuggestions:
enqueuePendingSearchSuggestionsIfNeeded(
@@ -1340,6 +1360,16 @@ const deriveHiddenCollectionSummaries = (
return hiddenCollectionSummaries;
};
+/**
+ * Return the ID of the collection summary that should be shown when the user
+ * navigates to the uncategorized section.
+ */
+const deriveUncategorizedCollectionSummaryID = (
+ normalCollections: Collection[],
+) =>
+ normalCollections.find(({ type }) => type == "uncategorized")?.id ??
+ CollectionSummaryID.uncategorizedPlaceholder;
+
const createCollectionSummaries = (
user: User,
collections: Collection[],
diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.ts
index 8f0d0daff6..0dd687425c 100644
--- a/web/packages/new/photos/services/collection-summary.ts
+++ b/web/packages/new/photos/services/collection-summary.ts
@@ -43,6 +43,8 @@ export const CollectionSummaryID = {
/**
* A placeholder for the uncategorized collection used till it is empty.
*
+ * [Note: Uncategorized placeholder]
+ *
* The user's sole "uncategorized" collection is created on demand the first
* time we need to move a file out of the last collection it belonged to
* (yet retain the file).