/** * 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( files: readonly TFile[], upload: (file: TFile) => Promise, setPending: (pending: boolean) => void, ): Promise { if (files.length === 0) { return; } setPending(true); try { for (const file of files) { await upload(file); } } finally { setPending(false); } }