Skip to content

armgit / ente

Public Imported from GitHub
0

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

conv

Manav Rathi5e0991aa9cb7
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 51bdcfab75..9acc20062b 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -132,7 +132,7 @@ import {
handleCollectionOp,
type CollectionOp,
} from "utils/collection";
-import { type FileOp, getSelectedFiles, handleFileOp } from "utils/file";
+import { getSelectedFiles, handleFileOp, type FileOp } from "utils/file";
const defaultGalleryContext: GalleryContextType = {
setActiveCollectionID: () => null,
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index d4e4c9b7b5..b19f0366f3 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -8,7 +8,7 @@ import {
CollectionMagicMetadata,
CollectionMagicMetadataProps,
CollectionPublicMagicMetadata,
- CollectionType,
+ type CollectionType,
CreatePublicAccessTokenRequest,
EncryptedCollection,
PublicURL,
@@ -58,7 +58,7 @@ const FAVORITE_COLLECTION_NAME = "Favorites";
const REQUEST_BATCH_SIZE = 1000;
export const createAlbum = (albumName: string) => {
- return createCollection(albumName, CollectionType.album);
+ return createCollection(albumName, "album");
};
const createCollection = async (
@@ -136,7 +136,7 @@ const postCollection = async (
};
export const createFavoritesCollection = () => {
- return createCollection(FAVORITE_COLLECTION_NAME, CollectionType.favorites);
+ return createCollection(FAVORITE_COLLECTION_NAME, "favorites");
};
export const addToFavorites = async (
@@ -604,7 +604,7 @@ export const updateShareableURL = async (
export const getFavCollection = async () => {
const collections = await getLocalCollections();
for (const collection of collections) {
- if (collection.type === CollectionType.favorites) {
+ if (collection.type == "favorites") {
return collection;
}
}
@@ -662,17 +662,14 @@ export async function getUncategorizedCollection(
collections = await getLocalCollections();
}
const uncategorizedCollection = collections.find(
- (collection) => collection.type === CollectionType.uncategorized,
+ (collection) => collection.type == "uncategorized",
);
return uncategorizedCollection;
}
export function createUnCategorizedCollection() {
- return createCollection(
- UNCATEGORIZED_COLLECTION_NAME,
- CollectionType.uncategorized,
- );
+ return createCollection(UNCATEGORIZED_COLLECTION_NAME, "uncategorized");
}
export async function getDefaultHiddenCollection(): Promise<Collection> {
@@ -685,7 +682,7 @@ export async function getDefaultHiddenCollection(): Promise<Collection> {
}
export function createHiddenCollection() {
- return createCollection(HIDDEN_COLLECTION_NAME, CollectionType.album, {
+ return createCollection(HIDDEN_COLLECTION_NAME, "album", {
subType: SUB_TYPE.DEFAULT_HIDDEN,
visibility: ItemVisibility.hidden,
});
diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts
index 4787332ce5..1ece43eb8f 100644
--- a/web/apps/photos/src/utils/collection.ts
+++ b/web/apps/photos/src/utils/collection.ts
@@ -7,7 +7,6 @@ import {
type Collection,
CollectionMagicMetadataProps,
CollectionPublicMagicMetadataProps,
- CollectionType,
SUB_TYPE,
} from "@/media/collection";
import { EnteFile } from "@/media/file";
@@ -330,9 +329,9 @@ export function isValidReplacementAlbum(
) {
return (
collection.name === wantedCollectionName &&
- (collection.type === CollectionType.album ||
- collection.type === CollectionType.folder ||
- collection.type === CollectionType.uncategorized) &&
+ (collection.type == "album" ||
+ collection.type == "folder" ||
+ collection.type == "uncategorized") &&
!isHiddenCollection(collection) &&
!isQuickLinkCollection(collection) &&
!isIncomingShare(collection, user)
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index a813afaed3..07784ae074 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -6,12 +6,7 @@ import { ItemVisibility } from "@/media/file-metadata";
// TODO: Audit this file
-export enum CollectionType {
- folder = "folder",
- favorites = "favorites",
- album = "album",
- uncategorized = "uncategorized",
-}
+export type CollectionType = "folder" | "favorites" | "album" | "uncategorized";
export enum COLLECTION_ROLE {
VIEWER = "VIEWER",
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index abb8418870..257c976529 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -2,11 +2,7 @@ import {
isArchivedCollection,
isPinnedCollection,
} from "@/gallery/services/magic-metadata";
-import {
- COLLECTION_ROLE,
- CollectionType,
- type Collection,
-} from "@/media/collection";
+import { COLLECTION_ROLE, type Collection } from "@/media/collection";
import type { EnteFile, FilePrivateMagicMetadata } from "@/media/file";
import { mergeMetadata } from "@/media/file";
import { isArchivedFile } from "@/media/file-metadata";
@@ -1221,7 +1217,7 @@ const deriveFavoriteFileIDs = (
) => {
let favoriteFileIDs = new Set<number>();
for (const collection of collections) {
- if (collection.type === CollectionType.favorites) {
+ if (collection.type == "favorites") {
favoriteFileIDs = new Set(
files
.filter((file) => file.collectionID === collection.id)
@@ -1254,7 +1250,7 @@ const deriveNormalCollectionSummaries = (
);
const uncategorizedCollection = normalCollections.find(
- ({ type }) => type === CollectionType.uncategorized,
+ ({ type }) => type == "uncategorized",
);
if (!uncategorizedCollection) {
normalCollectionSummaries.set(DUMMY_UNCATEGORIZED_COLLECTION, {
@@ -1365,23 +1361,7 @@ const createCollectionSummaries = (
} else if (isPinnedCollection(collection)) {
type = "pinned";
} else {
- // Directly use the collection type
- // TODO: The constants can be aligned once collection type goes from
- // an enum to an union.
- switch (collection.type) {
- case CollectionType.folder:
- type = "folder";
- break;
- case CollectionType.favorites:
- type = "favorites";
- break;
- case CollectionType.album:
- type = "album";
- break;
- case CollectionType.uncategorized:
- type = "uncategorized";
- break;
- }
+ type = collection.type;
}
// This block of code duplicates the above. Such duplication is needed
@@ -1409,20 +1389,9 @@ const createCollectionSummaries = (
if (isPinnedCollection(collection)) {
attributes.push("pinned");
}
- switch (collection.type) {
- case CollectionType.folder:
- attributes.push("folder");
- break;
- case CollectionType.favorites:
- attributes.push("favorites");
- break;
- case CollectionType.album:
- attributes.push("album");
- break;
- case CollectionType.uncategorized:
- attributes.push("uncategorized");
- break;
- }
+ // TODO: Verify type before removing the null check.
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+ if (collection.type) attributes.push(collection.type);
let name: string;
if (type == "uncategorized") {
diff --git a/web/packages/new/photos/services/collection/ui.ts b/web/packages/new/photos/services/collection/ui.ts
index 6b9340def6..104fbe7352 100644
--- a/web/packages/new/photos/services/collection/ui.ts
+++ b/web/packages/new/photos/services/collection/ui.ts
@@ -1,12 +1,10 @@
+import type { CollectionType } from "@/media/collection";
import type { EnteFile } from "@/media/file";
export type CollectionSummaryType =
- | "folder"
- | "favorites"
- | "album"
+ | CollectionType
| "archive"
| "trash"
- | "uncategorized"
| "all"
| "outgoingShare"
| "incomingShareViewer"