diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx index 7cbdb08984..d95f2215f9 100644 --- a/web/apps/photos/src/components/Upload/Uploader.tsx +++ b/web/apps/photos/src/components/Upload/Uploader.tsx @@ -10,7 +10,6 @@ import { UPLOAD_STAGES } from "@/new/photos/services/upload/types"; import { firstNonEmpty } from "@/utils/array"; import { ensure } from "@/utils/ensure"; import { CustomError } from "@ente/shared/error"; -import { isPromise } from "@ente/shared/utils"; import DiscFullIcon from "@mui/icons-material/DiscFull"; import UserNameInputDialog from "components/UserNameInputDialog"; import { t } from "i18next"; @@ -199,7 +198,7 @@ export default function Uploader({ */ const pickedUploadType = useRef(null); - const currentUploadPromise = useRef>(null); + const currentUploadPromise = useRef | undefined>(); const uploadRunning = useRef(false); const uploaderNameRef = useRef(null); const isDragAndDrop = useRef(false); @@ -555,15 +554,14 @@ export default function Uploader({ uploaderName?: string, ) => { const currentPromise = currentUploadPromise.current; - currentUploadPromise.current = waitAndRun( - currentPromise, - async () => - await uploadFiles( - uploadItemsWithCollection, - collections, - uploaderName, - ), - ); + currentUploadPromise.current = (async () => { + if (currentPromise) await currentPromise; + return uploadFiles( + uploadItemsWithCollection, + collections, + uploaderName, + ); + })(); await currentUploadPromise.current; }; @@ -802,16 +800,6 @@ export default function Uploader({ ); } -async function waitAndRun( - waitPromise: Promise, - task: () => Promise, -) { - if (waitPromise && isPromise(waitPromise)) { - await waitPromise; - } - await task(); -} - const desktopFilesAndZipItems = async (electron: Electron, files: File[]) => { const fileAndPaths: FileAndPath[] = []; let zipItems: ZipItem[] = []; diff --git a/web/packages/shared/utils/index.ts b/web/packages/shared/utils/index.ts index 101e6eb27f..d8aae6cb55 100644 --- a/web/packages/shared/utils/index.ts +++ b/web/packages/shared/utils/index.ts @@ -20,10 +20,6 @@ export function downloadUsingAnchor(link: string, name: string) { a.remove(); } -export function isPromise(obj: T | Promise): obj is Promise { - return obj && typeof (obj as any).then === "function"; -} - export async function retryAsyncFunction( request: (abort?: () => void) => Promise, waitTimeBeforeNextTry?: number[],