Skip to content

armgit / ente

Public Imported from GitHub
0

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

fin move of derived state to reducer file

Manav Rathi9db7a780e016
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
index 599c7348ec..85d317575b 100644
--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
@@ -9,6 +9,7 @@ import {
GalleryItemsSummary,
} from "@/new/photos/components/gallery/ListHeader";
import { SpaceBetweenFlex } from "@/new/photos/components/mui";
+import { ALL_SECTION, HIDDEN_ITEMS_SECTION } from "@/new/photos/services/collection";
import type {
CollectionSummary,
CollectionSummaryType,
@@ -49,13 +50,11 @@ import * as CollectionAPI from "services/collectionService";
import * as TrashService from "services/trashService";
import { SetFilesDownloadProgressAttributesCreator } from "types/gallery";
import {
- ALL_SECTION,
changeCollectionOrder,
changeCollectionSortOrder,
changeCollectionVisibility,
downloadCollectionHelper,
downloadDefaultHiddenCollectionHelper,
- HIDDEN_ITEMS_SECTION,
isHiddenCollection,
} from "utils/collection";
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 60752670f2..d9c7d35f71 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -5,6 +5,7 @@ import {
type GalleryBarImplProps,
} from "@/new/photos/components/gallery/BarImpl";
import { PeopleHeader } from "@/new/photos/components/gallery/PeopleHeader";
+import { ALL_SECTION } from "@/new/photos/services/collection";
import {
areOnlySystemCollections,
collectionsSortBy,
@@ -26,7 +27,6 @@ import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { sortCollectionSummaries } from "services/collectionService";
import { SetFilesDownloadProgressAttributesCreator } from "types/gallery";
-import { ALL_SECTION } from "utils/collection";
import {
FilesDownloadProgressAttributes,
isFilesDownloadCancelled,
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 5f650b8949..659fcc99c1 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -4,7 +4,7 @@ import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { useModalVisibility } from "@/base/components/utils/modal";
import { useIsSmallWidth } from "@/base/hooks";
import log from "@/base/log";
-import { CollectionType, type Collection } from "@/media/collection";
+import { type Collection } from "@/media/collection";
import { mergeMetadata, type EnteFile } from "@/media/file";
import {
CollectionSelector,
@@ -20,9 +20,20 @@ import {
SearchResultsHeader,
} from "@/new/photos/components/gallery";
import type { GalleryBarMode } from "@/new/photos/components/gallery/BarImpl";
-import { useGalleryReducer } from "@/new/photos/components/gallery/reducer";
+import {
+ getUniqueFiles,
+ setDerivativeState,
+ useGalleryReducer,
+} from "@/new/photos/components/gallery/reducer";
import { usePeopleStateSnapshot } from "@/new/photos/components/utils/ml";
import { shouldShowWhatsNew } from "@/new/photos/services/changelog";
+import {
+ ALL_SECTION,
+ ARCHIVE_SECTION,
+ DUMMY_UNCATEGORIZED_COLLECTION,
+ HIDDEN_ITEMS_SECTION,
+ TRASH_SECTION,
+} from "@/new/photos/services/collection";
import type { CollectionSummaries } from "@/new/photos/services/collection/ui";
import { areOnlySystemCollections } from "@/new/photos/services/collection/ui";
import downloadManager from "@/new/photos/services/download";
@@ -31,6 +42,7 @@ import {
getLocalTrashedFiles,
sortFiles,
} from "@/new/photos/services/files";
+import { isArchivedFile } from "@/new/photos/services/magic-metadata";
import type { Person } from "@/new/photos/services/ml/people";
import {
filterSearchableFiles,
@@ -110,10 +122,7 @@ import {
createUnCategorizedCollection,
getAllLatestCollections,
getAllLocalCollections,
- getCollectionSummaries,
getFavItemIds,
- getHiddenItemsSummary,
- getSectionSummaries,
} from "services/collectionService";
import { syncFiles } from "services/fileService";
import { preFileInfoSync, sync } from "services/sync";
@@ -129,15 +138,8 @@ import {
import { FamilyData } from "types/user";
import { checkSubscriptionPurchase } from "utils/billing";
import {
- ALL_SECTION,
- ARCHIVE_SECTION,
COLLECTION_OPS_TYPE,
- DUMMY_UNCATEGORIZED_COLLECTION,
- HIDDEN_ITEMS_SECTION,
- TRASH_SECTION,
constructCollectionNameMap,
- getArchivedCollections,
- getDefaultHiddenCollectionIDs,
getSelectedCollection,
handleCollectionOps,
splitNormalAndHiddenCollections,
@@ -146,10 +148,8 @@ import {
FILE_OPS_TYPE,
constructFileToCollectionMap,
getSelectedFiles,
- getUniqueFiles,
handleFileOps,
} from "utils/file";
-import { isArchivedFile } from "@/new/photos/services/magic-metadata";
import { getSessionExpiredMessage } from "utils/ui";
import { getLocalFamilyData } from "utils/user/family";
@@ -444,7 +444,14 @@ export default function Gallery() {
if (!user || !files || !collections || !hiddenFiles || !trashedFiles) {
return;
}
- setDerivativeState(
+ const {
+ favItemIds,
+ archivedCollections,
+ defaultHiddenCollectionIDs,
+ hiddenFileIds,
+ mergedCollectionSummaries,
+ hiddenCollectionSummaries,
+ } = setDerivativeState(
user,
collections,
hiddenCollections,
@@ -452,6 +459,12 @@ export default function Gallery() {
trashedFiles,
hiddenFiles,
);
+ setFavItemIds(favItemIds);
+ setArchivedCollections(archivedCollections);
+ setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);
+ setHiddenFileIds(hiddenFileIds);
+ setCollectionSummaries(mergedCollectionSummaries);
+ setHiddenCollectionSummaries(hiddenCollectionSummaries);
}, [
collections,
hiddenCollections,
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 98ff337c8f..998a75603e 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -8,7 +8,6 @@ import {
CollectionMagicMetadataProps,
CollectionPublicMagicMetadata,
CollectionShareeMagicMetadata,
- CollectionToFileMap,
CollectionType,
CreatePublicAccessTokenRequest,
EncryptedCollection,
@@ -21,22 +20,15 @@ import {
} from "@/media/collection";
import { EncryptedMagicMetadata, EnteFile } from "@/media/file";
import { ItemVisibility } from "@/media/file-metadata";
-import type {
- CollectionSummaries,
- CollectionSummary,
- CollectionSummaryType,
-} from "@/new/photos/services/collection/ui";
+import { isDefaultHiddenCollection } from "@/new/photos/services/collection";
+import type { CollectionSummary } from "@/new/photos/services/collection/ui";
import {
CollectionSummaryOrder,
CollectionsSortBy,
} from "@/new/photos/services/collection/ui";
+import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
import { getLocalFiles, sortFiles } from "@/new/photos/services/files";
-import {
- isArchivedCollection,
- isArchivedFile,
- isPinnedCollection,
- updateMagicMetadata,
-} from "@/new/photos/services/magic-metadata";
+import { updateMagicMetadata } from "@/new/photos/services/magic-metadata";
import { batch } from "@/utils/array";
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
@@ -45,27 +37,15 @@ import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
import { getActualKey } from "@ente/shared/user";
import type { User } from "@ente/shared/user/types";
-import { t } from "i18next";
import { FamilyData } from "types/user";
import {
- ALL_SECTION,
- ARCHIVE_SECTION,
- DUMMY_UNCATEGORIZED_COLLECTION,
- HIDDEN_ITEMS_SECTION,
- TRASH_SECTION,
changeCollectionSubType,
getHiddenCollections,
getNonHiddenCollections,
- isDefaultHiddenCollection,
isHiddenCollection,
- isIncomingCollabShare,
- isIncomingShare,
- isOutgoingShare,
isQuickLinkCollection,
- isSharedOnlyViaLink,
isValidMoveTarget,
} from "utils/collection";
-import { getUniqueFiles, groupFilesBasedOnCollectionID } from "utils/file";
import { UpdateMagicMetadataRequest } from "./fileService";
import { getPublicKey } from "./userService";
diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.ts
index 8b7dfceb10..9f727f9b90 100644
--- a/web/apps/photos/src/services/watch.ts
+++ b/web/apps/photos/src/services/watch.ts
@@ -13,6 +13,7 @@ import type {
} from "@/base/types/ipc";
import type { Collection } from "@/media/collection";
import { EncryptedEnteFile } from "@/media/file";
+import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
import { getLocalFiles } from "@/new/photos/services/files";
import { UPLOAD_RESULT } from "@/new/photos/services/upload/types";
import { ensureString } from "@/utils/ensure";
@@ -20,7 +21,6 @@ import debounce from "debounce";
import uploadManager, {
type UploadItemWithCollection,
} from "services/upload/uploadManager";
-import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
import { removeFromCollection } from "./collectionService";
/**
diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts
index 0966442105..c637e71123 100644
--- a/web/apps/photos/src/utils/collection.ts
+++ b/web/apps/photos/src/utils/collection.ts
@@ -10,7 +10,11 @@ import {
} from "@/media/collection";
import { EnteFile } from "@/media/file";
import { ItemVisibility } from "@/media/file-metadata";
-import { getDefaultHiddenCollectionIDs, isDefaultHiddenCollection, isIncomingShare } from "@/new/photos/services/collection";
+import {
+ getDefaultHiddenCollectionIDs,
+ isDefaultHiddenCollection,
+ isIncomingShare,
+} from "@/new/photos/services/collection";
import { getAllLocalFiles, getLocalFiles } from "@/new/photos/services/files";
import {
isArchivedCollection,
@@ -39,8 +43,6 @@ import {
import { SetFilesDownloadProgressAttributes } from "types/gallery";
import { downloadFilesWithProgress } from "utils/file";
-
-
export enum COLLECTION_OPS_TYPE {
ADD,
MOVE,
@@ -350,8 +352,6 @@ export const isHiddenCollection = (collection: Collection) =>
export const isQuickLinkCollection = (collection: Collection) =>
collection.magicMetadata?.data.subType === SUB_TYPE.QUICK_LINK_COLLECTION;
-
-
export function isIncomingViewerShare(collection: Collection, user: User) {
const sharee = collection.sharees?.find((sharee) => sharee.id === user.id);
return sharee?.role === COLLECTION_ROLE.VIEWER;
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index e74b9f27b4..a80a3fdae7 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -1,4 +1,5 @@
import { FileType } from "@/media/file-type";
+import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
import { getLocalFiles } from "@/new/photos/services/files";
import { getLocalCollections } from "services/collectionService";
import { parseDateFromDigitGroups } from "services/upload/date";
@@ -9,7 +10,6 @@ import {
getMetadataJSONMapKeyForJSON,
} from "services/upload/takeout";
import { getUserDetailsV2 } from "services/userService";
-import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
const DATE_TIME_PARSING_TEST_FILE_NAMES = [
{
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index b1bea603d6..910dc052af 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -1,4 +1,3 @@
-import type { EnteFile } from "@/media/file";
import {
type EncryptedMagicMetadata,
type MagicMetadataCore,
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 90661ee815..bcc4ae9baa 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -1,6 +1,5 @@
//TODO Review entire file
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
-/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { CollectionType, type Collection } from "@/media/collection";
import type { EnteFile } from "@/media/file";
@@ -110,14 +109,17 @@ export const setDerivativeState = (
break;
}
}
- setFavItemIds(favItemIds);
+ // TODO: Move to reducer
+ // setFavItemIds(favItemIds);
const archivedCollections = getArchivedCollections(collections);
- setArchivedCollections(archivedCollections);
+ // TODO: Move to reducer
+ // setArchivedCollections(archivedCollections);
const defaultHiddenCollectionIDs =
getDefaultHiddenCollectionIDs(hiddenCollections);
- setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);
+ // setDefaultHiddenCollectionIDs(defaultHiddenCollectionIDs);
const hiddenFileIds = new Set<number>(hiddenFiles.map((f) => f.id));
- setHiddenFileIds(hiddenFileIds);
+ // TODO: Move to reducer
+ // setHiddenFileIds(hiddenFileIds);
const collectionSummaries = getCollectionSummaries(
user,
collections,
@@ -138,8 +140,23 @@ export const setDerivativeState = (
hiddenCollections,
);
hiddenCollectionSummaries.set(HIDDEN_ITEMS_SECTION, hiddenItemsSummaries);
- setCollectionSummaries(mergeMaps(collectionSummaries, sectionSummaries));
- setHiddenCollectionSummaries(hiddenCollectionSummaries);
+ // TODO: Move to reducer
+ const mergedCollectionSummaries = mergeMaps(
+ collectionSummaries,
+ sectionSummaries,
+ );
+ // setCollectionSummaries(mergeMaps(collectionSummaries, sectionSummaries));
+ // TODO: Move to reducer
+ // setHiddenCollectionSummaries(hiddenCollectionSummaries);
+
+ return {
+ favItemIds,
+ archivedCollections,
+ defaultHiddenCollectionIDs,
+ hiddenFileIds,
+ mergedCollectionSummaries,
+ hiddenCollectionSummaries,
+ };
};
export function getUniqueFiles(files: EnteFile[]) {
@@ -384,7 +401,7 @@ export function getArchivedSectionSummary(
coverFile: null,
// @ts-expect-error TODO Review types
latestFile: archivedFiles?.[0],
- fileCount: archivedFiles?.length,
+ fileCount: archivedFiles?.length ?? 0,
// @ts-expect-error TODO Review types
updationTime: archivedFiles?.[0]?.updationTime,
};
diff --git a/web/packages/new/photos/services/collection/index.ts b/web/packages/new/photos/services/collection/index.ts
index bf24e4aa21..1ce28c63cd 100644
--- a/web/packages/new/photos/services/collection/index.ts
+++ b/web/packages/new/photos/services/collection/index.ts
@@ -25,6 +25,8 @@ export function isIncomingShare(collection: Collection, user: User) {
}
export function isIncomingCollabShare(collection: Collection, user: User) {
+ // TODO: Need to audit the types
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const sharee = collection.sharees?.find((sharee) => sharee.id === user.id);
return sharee?.role === COLLECTION_ROLE.COLLABORATOR;
}