Skip to content

Commit 40f2250

Browse files
committed
Add explicit loading flag
1 parent 3f643bd commit 40f2250

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

web/src/lib/diff-viewer-multi-file.svelte.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ export class MultiFileDiffViewerState {
338338
activeSearchResult: ActiveSearchResult | null = $state(null);
339339
sidebarCollapsed = $state(false);
340340
diffMetadata: DiffMetadata | null = $state(null);
341-
readonly progressBar = $state(new ProgressBarState(100, 100));
341+
loading: boolean = $state(false);
342+
readonly progressBar = $state(new ProgressBarState(null, 100));
342343

343344
readonly fileTreeFilterDebounced = new Debounced(() => this.fileTreeFilter, 500);
344345
readonly searchQueryDebounced = new Debounced(() => this.searchQuery, 500);
@@ -478,8 +479,13 @@ export class MultiFileDiffViewerState {
478479
}
479480

480481
async loadPatches(meta: () => Promise<DiffMetadata>, patches: () => Promise<AsyncGenerator<FileDetails, void>>) {
482+
if (this.loading) {
483+
alert("Already loading patches, please wait.");
484+
return false;
485+
}
481486
try {
482487
this.progressBar.setSpinning();
488+
this.loading = true;
483489
await tick();
484490
await animationFramePromise();
485491

@@ -510,9 +516,7 @@ export class MultiFileDiffViewerState {
510516
alert("Failed to load patches: " + e);
511517
return false;
512518
} finally {
513-
if (!this.progressBar.isDone()) {
514-
this.progressBar.setProgress(100, 100);
515-
}
519+
this.loading = false;
516520
}
517521
}
518522

web/src/routes/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
</SettingsPopover>
139139
{/snippet}
140140

141-
{#if !viewer.progressBar.isDone()}
141+
{#if viewer.loading}
142142
<div class="absolute bottom-1/2 left-1/2 z-50 -translate-x-1/2 translate-y-1/2 rounded-full border bg-neutral p-2 shadow-md">
143143
<ProgressBar bind:state={viewer.progressBar} class="h-2 w-32" />
144144
</div>

web/src/routes/OpenDiffDialog.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
status = "renamed_modified";
119119
}
120120
121-
viewer.progressBar.setSpinning();
122121
const img = makeImageDetails(fileAMeta.name, fileBMeta.name, status, blobA, blobB);
123122
img.image.load = true; // load images by default when comparing two files directly
124123
yield img;
@@ -136,7 +135,6 @@
136135
return;
137136
}
138137
139-
viewer.progressBar.setSpinning();
140138
const diff = createTwoFilesPatch(fileAMeta.name, fileBMeta.name, textA, textB);
141139
let status: FileStatus = "modified";
142140
if (fileAMeta.name !== fileBMeta.name) {

0 commit comments

Comments
 (0)