shoc-frontend-new/src/domain/work-orders/utils/run-sequential-uploads.ts
Arthur Bassi d72be8c505 fix(work-orders): use local calendar day for slide-over completedDate
[recover] remove malicious eslint payload (was 6a278c01)
2026-08-10 17:12:13 -03:00

24 lines
650 B
TypeScript

/**
* Runs file uploads one-by-one while holding an aggregate pending flag true
* until every file has settled (success or failure). Avoids relying on a single
* TanStack Mutation `isPending`, which can flip false when a later small file
* finishes before an earlier large one.
*/
export async function runSequentialUploads<TFile>(
files: readonly TFile[],
upload: (file: TFile) => Promise<unknown>,
setPending: (pending: boolean) => void,
): Promise<void> {
if (files.length === 0) {
return;
}
setPending(true);
try {
for (const file of files) {
await upload(file);
}
} finally {
setPending(false);
}
}