Skip to content

Commit

Permalink
Inline
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvr committed Sep 7, 2024
1 parent 31bfb53 commit d2deea9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
30 changes: 9 additions & 21 deletions web/apps/photos/src/components/Upload/Uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -199,7 +198,7 @@ export default function Uploader({
*/
const pickedUploadType = useRef<PICKED_UPLOAD_TYPE>(null);

const currentUploadPromise = useRef<Promise<void>>(null);
const currentUploadPromise = useRef<Promise<void> | undefined>();
const uploadRunning = useRef(false);
const uploaderNameRef = useRef<string>(null);
const isDragAndDrop = useRef(false);
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -802,16 +800,6 @@ export default function Uploader({
);
}

async function waitAndRun(
waitPromise: Promise<void>,
task: () => Promise<void>,
) {
if (waitPromise && isPromise(waitPromise)) {
await waitPromise;
}
await task();
}

const desktopFilesAndZipItems = async (electron: Electron, files: File[]) => {
const fileAndPaths: FileAndPath[] = [];
let zipItems: ZipItem[] = [];
Expand Down
4 changes: 0 additions & 4 deletions web/packages/shared/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export function downloadUsingAnchor(link: string, name: string) {
a.remove();
}

export function isPromise<T>(obj: T | Promise<T>): obj is Promise<T> {
return obj && typeof (obj as any).then === "function";
}

export async function retryAsyncFunction<T>(
request: (abort?: () => void) => Promise<T>,
waitTimeBeforeNextTry?: number[],
Expand Down

0 comments on commit d2deea9

Please sign in to comment.