Skip to content

armgit / ente

Public Imported from GitHub
0

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

refractor(FileListWithViewer):cutting-down-scope-removing-editor-changes

Aswin Asok9a159acbbb85
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 186e46e046..5dd07d3aeb 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -16,23 +16,14 @@ import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
-import {
- addOrCopyToCollection,
- canDirectlyUploadToCollection,
- canUploadToCollection,
- moveToTrash,
- savedOrCreateUserUncategorizedCollection,
-} from "ente-new/photos/services/collection";
+import { moveToTrash } from "ente-new/photos/services/collection";
import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { updateMapEnabled } from "ente-new/photos/services/settings";
import { t } from "i18next";
import { useCallback, useEffect, useMemo, useState } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
-import {
- successfulFilesFromUploadBatchResult,
- uploadManager,
-} from "services/upload-manager";
+import { uploadManager } from "services/upload-manager";
import {
FileList,
type FileListAnnotatedFile,
@@ -280,60 +271,16 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
const handleSaveEditedImageCopy = useMemo(() => {
if (!enableImageEditing) return undefined;
- return async (
+ return (
editedFile: File,
collection: Collection,
enteFile: EnteFile,
) => {
- let processedAny = false;
- try {
- await uploadManager.waitUntilIdle();
- await onRemotePull();
- uploadManager.prepareForNewUpload();
- uploadManager.showUploadProgressDialog();
-
- const uploadCollection = canDirectlyUploadToCollection(
- collection,
- )
- ? collection
- : canUploadToCollection(collection)
- ? await savedOrCreateUserUncategorizedCollection()
- : undefined;
-
- if (!uploadCollection) {
- throw new Error(
- "Upload not allowed for the selected collection",
- );
- }
-
- const batchResult = await uploadManager.uploadFile(
- editedFile,
- uploadCollection,
- enteFile,
- );
- processedAny = batchResult.processedAny;
- if (!processedAny) {
- uploadManager.hideUploadProgressDialog();
- return;
- }
-
- if (uploadCollection.id != collection.id) {
- const uploadedFiles =
- successfulFilesFromUploadBatchResult(batchResult);
- if (uploadedFiles.length) {
- await addOrCopyToCollection(collection, uploadedFiles);
- }
- }
- await onRemotePull();
- } catch (e) {
- if (processedAny) {
- await onRemotePull().catch(() => undefined);
- }
- uploadManager.hideUploadProgressDialog();
- onGenericError(e);
- }
+ uploadManager.prepareForNewUpload();
+ uploadManager.showUploadProgressDialog();
+ void uploadManager.uploadFile(editedFile, collection, enteFile);
};
- }, [enableImageEditing, onGenericError, onRemotePull]);
+ }, [enableImageEditing]);
const shouldShowMapButton =
modePlus !== "search" &&
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index d29f9ef441..4aef1fcc91 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -278,6 +278,11 @@ export const Upload: React.FC<UploadProps> = ({
const currentUploadPromise = useRef<Promise<void> | undefined>(undefined);
const uploadRunning = useRef(false);
const isDragAndDrop = useRef(false);
+
+ /**
+ * Used to remember a deferred "real destination" collectionf or the current upload flow.
+ * So this ref remembers the original shared album target across failed uploads.
+ */
const retrySharedAlbumUploadTarget = useRef<Collection | undefined>(
undefined,
);
@@ -717,10 +722,14 @@ export const Upload: React.FC<UploadProps> = ({
onGenericError(e);
return;
}
- await waitInQueueAndUploadFiles(uploadItemsWithCollection, collections, {
- persistPendingUploads: true,
- postUploadTargetCollection: undefined,
- });
+ await waitInQueueAndUploadFiles(
+ uploadItemsWithCollection,
+ collections,
+ {
+ persistPendingUploads: true,
+ postUploadTargetCollection: undefined,
+ },
+ );
uploadItemsAndPaths.current = [];
};
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index 0edcc159fe..5956dd3b01 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -640,10 +640,6 @@ class UploadManager {
};
}
- public waitUntilIdle = async () => {
- while (this.isUploadInProgress()) await wait(100);
- };
-
private updateExistingFiles(file: EnteFile) {
this.existingFiles.push(file);
this.onUploadFile!(file);
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 14080f76b4..9887004626 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -566,7 +566,7 @@ const currentUserRoleInCollection = (collection: Collection) => {
* only the OWNER, ADMIN and COLLABORATOR can actually add
* file to a collection
*/
-export const canAddFilesToCollection = (collection: Collection) => {
+const canAddFilesToCollection = (collection: Collection) => {
const role = currentUserRoleInCollection(collection);
return role == "OWNER" || role == "ADMIN" || role == "COLLABORATOR";
};
@@ -804,7 +804,7 @@ export const copyFiles = async (
return copiedFiles;
};
-export const savedUserUncategorizedCollection = async () => {
+const savedUserUncategorizedCollection = async () => {
const userID = ensureLocalUser().id;
return (await savedCollections()).find(
(collection) =>