feat(bulk-upload): guard save() against concurrent invocations
Adds a saving $state flag that blocks re-entry while a chunk upload is in flight. The UploadSaveBar save button is disabled via a new disabled prop while saving is true. Tested: clicking Save twice fires fetch only once. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ let {
|
||||
let files = new SvelteMap<string, FileEntry>();
|
||||
let activeId = $state<string | null>(null);
|
||||
let chunkProgress = $state<{ done: number; total: number } | undefined>(undefined);
|
||||
let saving = $state(false);
|
||||
|
||||
// --- Shared metadata ---
|
||||
let senderId = $state(untrack(() => initialSenderId));
|
||||
@@ -84,6 +85,8 @@ onDestroy(() => {
|
||||
|
||||
// --- Save ---
|
||||
async function save() {
|
||||
if (saving) return;
|
||||
saving = true;
|
||||
const entries = Array.from(files.values());
|
||||
const chunkSize = 10;
|
||||
const chunks: FileEntry[][] = [];
|
||||
@@ -124,6 +127,7 @@ async function save() {
|
||||
}
|
||||
chunkProgress = { done: i + 1, total: chunks.length };
|
||||
}
|
||||
saving = false;
|
||||
if (!hadErrors) goto('/documents');
|
||||
}
|
||||
</script>
|
||||
@@ -276,6 +280,7 @@ async function save() {
|
||||
chunkProgress={chunkProgress}
|
||||
onSave={save}
|
||||
onDiscard={discardAll}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user